[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

xml-rpc client result

Steve Ross

12/20/2007 6:03:00 PM

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

7 Answers

James Gray

12/20/2007 6:31:00 PM

0

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.xmlrp...

Looks like you are dealing with a custom protocol here.

James Edward Gray II

Steve Ross

12/20/2007 7:12:00 PM

0

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.xmlrp...
>
> 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

Steve Ross

12/20/2007 10:58:00 PM

0

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.xmlrp...
>
> Looks like you are dealing with a custom protocol here.
>
> James Edward Gray II
>


James Gray

12/20/2007 11:05:00 PM

0

On Dec 20, 2007, at 4:58 PM, s.ross wrote:

> 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=

Steve Ross

12/20/2007 11:35:00 PM

0

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, =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 =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



James Gray

12/21/2007 2:40:00 AM

0

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:
>>
>>> As a followup, I can parse the returned XML string using =20
>>> XmlSimple, which works ok. I just thought the parsing took place =20
>>> automagically in the XMLRPC parser.
>>
>> 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 =20
>> please show the full response, as you receive it? If those item =20
>> codes are returned inside of the <string> =85 </string> tags you =20
>> showed earlier, XML-RPC is just giving you what the XML said it =20
>> received, a String.
>>
>> James Edward Gray II
>
> 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=

> debug?

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

James Edward Gray II


Steve Ross

12/21/2007 4:21:00 AM

0

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

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.

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

--s