加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在Ruby中使用libxml解析SOAP响应

发布时间:2020-12-17 02:50:57 所属栏目:百科 来源:网络整理
导读:我试图解析来自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:retu
我试图解析来自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]

查看documentation

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读