2

I want to use w3c.dom to update xml and create a new file. I had use transform like this:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(newXml);
StreamResult result = new StreamResult(target);
transformer.transform(source, result);

I use setTextContent to update a document file to newxml, but the new file(result) encoding is different with newXml. I know that I can use

transformer.setOutputProperty(OutputKeys.ENCODING, newXml.getXmlEncoding());

but I hope the result document type and encoding typesetting is same with original file(newXml).

Hope someone to know how to do, thank you~

4

1 回答 1

0

您可以使用 base64 编码 - 解码模式。首先将 xml 转换为 base64,然后将其重新转换为 xml。

于 2012-07-26T06:39:44.500 回答