简体   繁体   中英

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. One little problem I am facing is that for XML payload in the SOAP body, < > are getting replaced by &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. I was doing
client = Savon::Client.new(wsdl: "")
result = client.call(...)
puts result

This was displaying &lt; and &gt;

The right way to access the response content in my case is
result.body[:index_response][:value]
result.body returns a hash

With Nokogiri I could do doc = Nokogiri::XML(result.body.to_xml)

This works well with XML in payload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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