xml-rpc client result

S

s.ross

I posted this on Nabble but don't think it made it through to the
list. Here's the q:

I can use the xmlrpc library to call a remote Web Service, but the
results appear always to be returned as an XML stream. The code
implies that the xml is parsed, and doing some messing with it in irb
shows that at some level, the result value can be treated as a hash.
I'm unable to determine to what extent. Consider a result such as:

<fineWebServiceResponse>
<itemList>
<item thingieId="1" />
<item thingieId="2" />
<item thingieId="3" />
</itemList>
</fineWebServiceResponse>

How do I get this into a parsed form such as a hash or array or
arrays? Or more correctly, what is the best way of iterating this data?

Thanks
 
J

James Gray

I can use the xmlrpc library to call a remote Web Service, but the
results appear always to be returned as an XML stream.
<fineWebServiceResponse>
<itemList>
<item thingieId="1" />
<item thingieId="2" />
<item thingieId="3" />
</itemList>
</fineWebServiceResponse>

This is not a valid XML-RPC response. You can read the spec at:

http://www.xmlrpc.com/spec

Looks like you are dealing with a custom protocol here.

James Edward Gray II
 
S

s.ross

This is not a valid XML-RPC response. You can read the spec at:

http://www.xmlrpc.com/spec

Looks like you are dealing with a custom protocol here.

James Edward Gray II

Well, I abbreviated the actual XML. Really:

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<methodResponse>
<params>
<param>
<value>
<string>
stuff
</string>
</value>
</param>
</params>
</methodResponse>

I'm looking at a ruby-debug dump of "data" from the call,
parser().parseMethodResponse(data). I think it's valid XML-RPC. Sorry
for the misleading trimming of the response.

Thx
 
S

s.ross

As a followup, I can parse the returned XML string using XmlSimple,
which works ok. I just thought the parsing took place automagically in
the XMLRPC parser.

--s
 
J

James Gray

As a followup, I can parse the returned XML string using XmlSimple, =20=
which works ok. I just thought the parsing took place automagically =20=
in the XMLRPC parser.

OK, forgive me for not getting this, but you've shown us two pieces of =20=

XML. One look XML-RPCish, but the other did not. Can you please show =20=

the full response, as you receive it? If those item codes are =20
returned inside of the <string> =85 </string> tags you showed earlier, =20=

XML-RPC is just giving you what the XML said it received, a String.

James Edward Gray II=
 
S

s.ross

OK, forgive me for not getting this, but you've shown us two pieces =20=
of XML. One look XML-RPCish, but the other did not. Can you please =20=
show the full response, as you receive it? If those item codes are =20=
returned inside of the <string> =85 </string> tags you showed earlier, = =20
XML-RPC is just giving you what the XML said it received, a String.

James Edward Gray II

No, forgive me for the sort of vague question. The Web Service =20
provider made me sign a contract not to blah, blah, blah... so I felt =20=

I should obfuscate a certain amount of this XML response. This is the =20=

actual XML with the service provider and member names changed to =20
protect the guilty. Again, when the string is returned, punching it =20
into XmlSimple allows me access to each member of the image =20
collection. However, it would be simpler to stay with one library if =20
possible.

<?xml version=3D\"1.0\" encoding=3D\"utf-8\"?>
<methodResponse>
<params>
<param>
<value>
<string>
<theWSResponse sessionid=3D"02632086050044137264314155577353" =20=

membername=3D"my_member_name">
<imageList>
<image fileid=3D"3782426" type=3D"Image" title=3D"Wide =
Angle of =20
777 Building""/>
<image fileid=3D"3782472" type=3D"Image" title=3D"Buoys for =
=20
Lobster Pots, Bar Harbor, Maine"/>
<image fileid=3D"3782503" type=3D"Image" title=3D"Ornate =
Clock =20
in Grand Central Station"/>
</imageList>
</theWSResponse>
</string>
</param>
</methodResponse>

By the way, is there a better way to get this raw data than in ruby-=20
debug?

Thanks again,

--s
 
J

James Gray

No, forgive me for the sort of vague question.

No worries. I get it now.
<?xml version=3D\"1.0\" encoding=3D\"utf-8\"?>
<methodResponse>
<params>
<param>
<value>
<string>
<theWSResponse sessionid=3D"02632086050044137264314155577353" =20=
membername=3D"my_member_name">
<imageList>
<image fileid=3D"3782426" type=3D"Image" title=3D"Wide = Angle of =20
777 Building""/>
<image fileid=3D"3782472" type=3D"Image" title=3D"Buoys for = =20
Lobster Pots, Bar Harbor, Maine"/>
<image fileid=3D"3782503" type=3D"Image" title=3D"Ornate = Clock =20
in Grand Central Station"/>
</imageList>
</theWSResponse>
</string>
</param>
</methodResponse>

Yeah, that's an odd use of XML-RPC structures. Instead of passing you =20=

an Array of Structs, which a library could completely extract, they =20
give you a custom XML protocol inside a normal String. Sad really as =20=

they clearly don't understand the point of XML-RPC.

There's no getting around it, you'll need to make a second XML parsing =20=

pass as you have mentioned doing.
By the way, is there a better way to get this raw data than in ruby-=20=

I'm not aware of an easy way to get the data, no.

James Edward Gray II
 
S

s.ross

[Note: parts of this message were removed to make it a legal post.]

Yeah, that's an odd use of XML-RPC structures. Instead of passing
you an Array of Structs, which a library could completely extract,
they give you a custom XML protocol inside a normal String. Sad
really as they clearly don't understand the point of XML-RPC.

Thanks so much for your help. At least I'm getting the data.

--s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top