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
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
···
On Dec 20, 2007, at 12:03 PM, s.ross wrote:
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>
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
···
On Dec 20, 2007, at 10:31 AM, James Gray wrote:
On Dec 20, 2007, at 12:03 PM, s.ross wrote:
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
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
···
On Dec 20, 2007, at 10:31 AM, James Gray wrote:
On Dec 20, 2007, at 12:03 PM, s.ross wrote:
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
OK, forgive me for not getting this, but you've shown us two pieces of XML. One look XML-RPCish, but the other did not. Can you please show the full response, as you receive it? If those item codes are returned inside of the <string> … </string> tags you showed earlier, XML-RPC is just giving you what the XML said it received, a String.
James Edward Gray II
···
On Dec 20, 2007, at 4:58 PM, s.ross wrote:
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.
No, forgive me for the sort of vague question. The Web Service provider made me sign a contract not to blah, blah, blah... so I felt I should obfuscate a certain amount of this XML response. This is the actual XML with the service provider and member names changed to protect the guilty. Again, when the string is returned, punching it into XmlSimple allows me access to each member of the image collection. However, it would be simpler to stay with one library if possible.
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<methodResponse>
<params>
<param>
<value>
<string>
<theWSResponse sessionid="02632086050044137264314155577353" membername="my_member_name">
<imageList>
<image fileid="3782426" type="Image" title="Wide Angle of 777 Building""/>
<image fileid="3782472" type="Image" title="Buoys for Lobster Pots, Bar Harbor, Maine"/>
<image fileid="3782503" type="Image" title="Ornate Clock 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-debug?
Thanks again,
--s
···
On Dec 20, 2007, at 3:05 PM, James Gray wrote:
On Dec 20, 2007, at 4:58 PM, s.ross wrote:
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.
OK, forgive me for not getting this, but you've shown us two pieces of XML. One look XML-RPCish, but the other did not. Can you please show the full response, as you receive it? If those item codes are returned inside of the <string> … </string> tags you showed earlier, XML-RPC is just giving you what the XML said it received, a String.
James Edward Gray II
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.
OK, forgive me for not getting this, but you've shown us two pieces of XML. One look XML-RPCish, but the other did not. Can you please show the full response, as you receive it? If those item codes are returned inside of the <string> … </string> tags you showed earlier, 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.
No worries. I get it now.
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<methodResponse>
<params>
<param>
<value>
<string>
<theWSResponse sessionid="02632086050044137264314155577353" membername="my_member_name">
<imageList>
<image fileid="3782426" type="Image" title="Wide Angle of 777 Building""/>
<image fileid="3782472" type="Image" title="Buoys for Lobster Pots, Bar Harbor, Maine"/>
<image fileid="3782503" type="Image" title="Ornate Clock in Grand Central Station"/>
</imageList>
</theWSResponse>
</string>
</param>
</methodResponse>
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.
There's no getting around it, you'll need to make a second XML parsing pass as you have mentioned doing.
By the way, is there a better way to get this raw data than in ruby-debug?
I'm not aware of an easy way to get the data, no.
James Edward Gray II
···
On Dec 20, 2007, at 5:35 PM, s.ross wrote:
On Dec 20, 2007, at 3:05 PM, James Gray wrote:
On Dec 20, 2007, at 4:58 PM, s.ross wrote:
Thanks so much for your help. At least I'm getting the data.
--s
···
On Dec 20, 2007, at 6:40 PM, James Gray wrote:
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.