[英]How can I extract/parse from this SOAP envelope using Ruby?
我正在使用使用soap / wsdlDriver的寶石。
發布后,我得到了SOAP響應,無法輕松解析它。
這是我得到的回復:
#<SOAP::Mapping::Object:0x159e95faf098 {}id="27b907f8-da51-f611-ab02-4c5f88a8ec8
8" {}error=#<SOAP::Mapping::Object:0x159e95fae33c {}number="0" {}name="No Error"
{}description="No Error">>
我需要在id =“ xxxx”中獲取整個值
這是在heroku上獲得的(注意:它在本地有效)。 這來自於測試response.id的各種變體(其中response.inspect是上面創建輸出的原因)
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事件:
好的,我有95%的把握是SOAP::Mapping::Object#inspect
的輸出,而不是實際的響應。 從該類中,您看起來可以使用[]
方法提取屬性。
因此,如果我沒看錯,那么您可能會想要:
response_id = response_object['id']
盡管每個屬性都以{}
開頭似乎很奇怪。 因此,如果這實際上是屬性名稱的一部分,則可能需要:
response_id = response_object['{}id']
但這似乎很奇怪,並且可能表明您正在使用的SOAP庫沒有正確解析響應。
免責聲明:我以前從未使用過這個庫,只是從仔細閱讀文檔中發布了這個庫。在描述此類的方式上,這可能是非常准確的。
我不知道如何用ruby做到這一點,但可能就像javascript中的這段代碼一樣。
var t = "<SOAP message........>";
var id = t.replace(/.*id=\"(.*?)\".*/, "$1");
正則表達式詳細信息:
.*id=\"(.*?)\".*
.* = anything, 0 or N times.
(.*?) = anything, 0 or N times, stopping at first match.
$1 = first group, the content inside ().
因此,所有內容都將被ID內容取代。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.