简体   繁体   中英

How can I extract/parse from this SOAP envelope using Ruby?

I am using a gem which uses soap/wsdlDriver.

When I post I get back a SOAP response and am unable to easily parse it.

This is the response I get back:

#<SOAP::Mapping::Object:0x159e95faf098 {}id="27b907f8-da51-f611-ab02-4c5f88a8ec8
8" {}error=#<SOAP::Mapping::Object:0x159e95fae33c {}number="0" {}name="No Error"
 {}description="No Error">>

I need to get the entire value in the id="xxxx"

This is what on get on heroku (note: it works locally). This comes from testing various variations of response.id (where response.inspect is what created the output above)

f" {}error=#> response[id] /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :77: warning: Object#id will be deprecated; use Object#object_id nil response.id: /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :79: warning: Object#id will be deprecated; use Object#object_id 23891500658740 /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :80: warning: Object#id will be deprecated; use Object#object_id this is the contact_id: 23891500658740 events:

Ok, I'm 95% sure that is the output of SOAP::Mapping::Object#inspect and not the actual response. And from that class it looks you use the [] method to pull out attributes.

So if I am reading that right, then it looks like you might want:

response_id = response_object['id']

Though each attribute being prefaced with {} seems pretty odd. So if that is actually part of the attribute name, you may need:

response_id = response_object['{}id']

But that seems pretty strange, and may indicate that the SOAP library you are using is not parsing the response properly.

Disclaimer: I've never used this lib before, and posted this from just perusing the docs... This may or may not be very accurate in the ways using this class is described.

I don't know how to do this with ruby, but may be like this code in javascript.

var t = "<SOAP message........>";
var id = t.replace(/.*id=\"(.*?)\".*/, "$1");

Regex details:

.*id=\"(.*?)\".*

.* = anything, 0 or N times.
(.*?) = anything, 0 or N times, stopping at first match.
$1 = first group, the content inside ().

So, everthing will be replaced by id content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM