ruby - 在 Ruby 中使用 libxml 解析 SOAP 响应

标签 ruby soap xmp

我正在尝试解析来自 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

关于ruby - 在 Ruby 中使用 libxml 解析 SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2722436/

相关文章:

c# - 为什么 Ruby 套接字服务器可以与其他 Ruby 套接字客户端配合使用,但不能与 C# 套接字客户端配合使用?

此实现的 Ruby 正确数据结构

java - 如何修复文件未将自身附加到 Java 中的 SAAJ SOAP 消息的问题?

r - 在 R 中,如果我有 Web 服务的 WSDL 描述,我该如何调用它? (消费网络服务)

pdf - 将 XMP 元数据嵌入 PDF

ios - 如何在 iOS 上将 XMP 元数据写入 QuickTime 视频?

ruby - 访问存储在实例变量中的线程的线程变量

javascript - 在 fb 共享时,在 fb_close 之后从 Rails 中的 Controller 调用 js 函数

web-services - Apache CXF + SpringBoot : Can I publish multiple endpoints for one SOAP web-service?

ios - 如何在 iOS 中设置 XMP 图像元数据?