我正在尝试解析来自 Savon SOAP api 的以下 SOAP 响应
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getConnectionResponse xmlns:ns="http://webservice.jchem.chemaxon">
<ns:return>
<ConnectionHandlerId>connectionHandlerID-283854719</ConnectionHandlerId>
</ns:return>
</ns:getConnectionResponse>
</soapenv:Body>
</soapenv:Envelope>
我尝试使用 libxml-ruby 但没有成功。基本上我想提取标签内的任何内容和 connectionHandlerID 值。
最佳答案
当您使用 Savon 时,您可以将响应转换为散列。转换方法 response.to_hash
也为您做了一些其他有用的事情。
然后您就可以使用类似于以下的代码来获取您想要的值
hres = soap_response.to_hash
conn_handler_id = hres[:get_connection_response][:return][:connection_handler_id]
关于ruby - 在 Ruby 中使用 libxml 解析 SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2722436/