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:
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?
Looks like you are dealing with a custom protocol here.
James Edward G. II
Well, I abbreviated the actual XML. Really:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
stuff
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.
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.
XML-RPC is just giving you what the XML said it received, a String.
James Edward G. II
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\"?>
By the way, is there a better way to get this raw data than in ruby-
debug?
please show the full response, as you receive it? If those item
codes are returned inside of the … tags you
showed earlier, XML-RPC is just giving you what the XML said it
received, a String.
James Edward G. II
No, forgive me for the sort of vague question.
No worries. I get it now.
777 Building""/>
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?
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.
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 … tags you showed earlier,
XML-RPC is just giving you what the XML said it received, a String.
James Edward G. II
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.