1

私は WebServiceTemplate クラスを使用しており、Web サービスから受け取った XML 応答をファイルに保存しています。しかし、.xml ファイルには、何らかの理由ですべての<、名前を付けて>保存された 、;&ltおよびが含まれてい;&gtます。

.xmlこれを保存する前に適切なファイルに変換する方法はありますか?

        InputStream inputStream = new   WebServiceClientImpl().getClass().getResourceAsStream("Request.xml");
        StreamSource source = new StreamSource(inputStream2);
        StreamResult result = new StreamResult(new File("Response.xml"));               
        webServiceTemplate.sendSourceAndReceiveToResult(defaultURI,source, result);

request.xml :

 <list>
 <requestXmlString xs:type="type:string" xmlns:xs="http://www.w3.org/2000/XMLSchema- instance">
 <![CDATA[<request operationName="list" locale="en">
     <resourceDescriptor name="" wsType="folder" uriString="/" isNew="false">
     <label>null</label>
     </resourceDescriptor>           
     </request>]]>
      </requestXmlString>
 </list>

Response.xml

  <?xml version="1.0" encoding="UTF-8"?><listResponse   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"   soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><listReturn   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;operationResult version="2.0.1"&gt;
&lt;returnCode&gt;&lt;![CDATA[0]]&gt;&lt;/returnCode&gt;
&lt;resourceDescriptor name="Record1" wsType="reportUnit"  uriString="/xyz" isNew="false"&gt;
    &lt;label&gt;&lt;![RECORD 1]]&gt;&lt;/label&gt;
    &lt;creationDate&gt;1338285680000&lt;/creationDate&gt;
    &lt;resourceProperty name="PROP_RESOURCE_TYPE"&gt;
        &lt;value&gt;&lt;!   
4

2 に答える 2

0

私はそれを考え出した!:)これを行うライブラリがあります。とてもシンプルです

StringEscapeUtils.unescapeXml(xml)

トリックを行います!

于 2012-10-19T09:14:20.873 に答える
0

ファイルへの書き込み中、< > & などの文字はシリアル化されるため、後で XML パーサーで読み取ることができます。

テキスト ノードで CDATA エンコーディングを試すことができます。この場合、CDATA ブロック内に < があります。

http://en.wikipedia.org/wiki/CDATA

于 2012-10-19T08:36:08.393 に答える