简体   繁体   English

wash_out | 有效负载中的XML具有<>而不是<>

[英]wash_out | XML in payload has &lt; &gt; instead of < >

wash_out (0.9.0) has been very helpful for me in implementing a SOAP service in my Rails(3.1) app. wash_out (0.9.0)对我在Rails(3.1)应用程序中实现SOAP服务非常有帮助。 One little problem I am facing is that for XML payload in the SOAP body, < > are getting replaced by &lt; &gt; 我面临的一个小问题是,对于SOAP正文中的XML有效负载, < >&lt; &gt;代替了&lt; &gt; &lt; &gt;

Here's my code snippet 这是我的代码段

render :soap => "<person><firstname>larry</firstname></person>"

Output is 输出是

<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.w3.org/2001/12/soap-envelope"> <soap:Body> <tns:index_response> <value xsi:type="xsd:string">&lt;person&gt;&lt;firstname&gt;larry&lt;/firstname&gt;&lt;/person&gt;</value> </tns:index_response> </soap:Body> </soap:Envelope>

Is this a bug or can I fix this by some configuration or additional code. 这是错误还是我可以通过一些配置或其他代码来解决。 Kindly help. 请帮助。

试试这个(没有测试):

render :soap => "<person><firstname>larry</firstname></person>".html_safe

I was able to resolve this. 我能够解决这个问题。 There was 1 thing I was doing wrong. 我做错了一件事情。

I am using savon client to call my SOAP service. 我正在使用savon客户端来调用我的SOAP服务。 I was doing 我在做
client = Savon::Client.new(wsdl: "")
result = client.call(...)
puts result

This was displaying &lt; 这是显示&lt; and &gt; &gt;

The right way to access the response content in my case is 就我而言,访问响应内容的正确方法是
result.body[:index_response][:value]
result.body returns a hash result.body返回哈希

With Nokogiri I could do doc = Nokogiri::XML(result.body.to_xml) 使用Nokogiri我可以做到doc = Nokogiri::XML(result.body.to_xml)

This works well with XML in payload. 这与有效负载中的XML很好地配合。

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

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