简体   繁体   English

如何使用Ruby从此SOAP信封中提取/解析?

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

I am using a gem which uses soap/wsdlDriver. 我正在使用使用soap / wsdlDriver的宝石。

When I post I get back a SOAP response and am unable to easily parse it. 发布后,我得到了SOAP响应,无法轻松解析它。

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" 我需要在id =“ xxxx”中获取整个值

This is what on get on heroku (note: it works locally). 这是在heroku上获得的(注意:它在本地有效)。 This comes from testing various variations of response.id (where response.inspect is what created the output above) 这来自于测试response.id的各种变体(其中response.inspect是上面创建输出的原因)

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: f“ {} error =#> response [id] /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb:77:警告:Object#id将被弃用;请使用Object#object_id nil response.id :/disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb:79:警告:Object#id将被弃用;请使用Object#object_id 23891500658740 / disk1 / home / slugs / 220752_47a08bb_10e7 / mnt / app / controllers /sugarcrm_controller.rb:80:警告:Object#id将被弃用;使用Object#object_id这是contact_id:23891500658740事件:

Ok, I'm 95% sure that is the output of SOAP::Mapping::Object#inspect and not the actual response. 好的,我有95%的把握是SOAP::Mapping::Object#inspect的输出,而不是实际的响应。 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. 但这似乎很奇怪,并且可能表明您正在使用的SOAP库没有正确解析响应。

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. 我不知道如何用ruby做到这一点,但可能就像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. 因此,所有内容都将被ID内容取代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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