我正在使用WebServiceTemplate類,並將從Web服務接收到的XML響應存儲在文件中。但.xml文件出於某種原因包含保存爲;<
和;>
的所有<
,>
。以Java保存.xml文件
有沒有什麼辦法可以在保存之前將其轉換爲正確的.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"><?xml version="1.0" encoding="UTF-8"?>
<operationResult version="2.0.1">
<returnCode><![CDATA[0]]></returnCode>
<resourceDescriptor name="Record1" wsType="reportUnit" uriString="/xyz" isNew="false">
<label><![RECORD 1]]></label>
<creationDate>1338285680000</creationDate>
<resourceProperty name="PROP_RESOURCE_TYPE">
<value><!
你能告訴我們你的代碼嗎? –
@Brian我已經添加了一些我的代碼片段。謝謝 – user1611418