如何在Soap UI中转义和号(&)

11
我正在使用来自SmartBear的Soap UI发送XML格式的SOAP请求,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsg="http://wsg.hpos.om.hp.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <wsg:abc>
      <wsg:contract>
         &lt;request&gt;

         &lt;request-attributes&gt;
            &lt;message&gt;"this &amp; and that"&lt;/message&gt;                
         &lt;/request-attributes&gt;             
         &lt;/request&gt;             
         </wsg:contract>
      </wsg:abc>
   </soapenv:Body>
</soapenv:Envelope>

响应为:“无效请求”。您能否解释如何转义&字符?谢谢。


& 转义了,但是为什么 <> 也被转义了呢? - Wooble
该应用程序无法读取合同正文中的<和>标记,因此必须使用其他表示方法代替<和>。类似地,当我尝试使用&替换&时,显然结果不正确。 - akc
6
好的,如果您正在对XML进行双重编码,是否尝试过使用&amp;amp; - Wooble
完美!! 它现在起作用了 :) 谢谢。你能告诉我这里的双重编码XML是什么吗? - akc
1
好的,大概你发送到的那个破损服务正在取消转义合同正文,然后解析生成的XML。 - Wooble
1个回答

20

你可以将有效负载包裹在 <![CDATA[]]> 中,不必担心转义:

<![CDATA[<request>    <request-attributes>        <message>"this & and that"</message>    </request-attributes> </request>]]>

1
您还可以根据需要将单个元素包装在CDATA中。 - Daniel Williams

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接