开发者

specifying newline type during xml serialization with LSOutput

I am serializing an org.w3c.dom.Document (stored in the variable开发者_运维百科 _document) to a text file (represented by the variable _file) using the snippet below. It works fine.

The file produced by the snippet has Unix-style newlines ('\n', 0x0A). However, this is running on Windows and I would like to have it use the DOS newline standard instead ( '\r\n', 0x0D0A) because the file will often be opened and read by administrators using notepad.exe.

Can I somehow specify the newline type to be used in the serialization below?

(In the snippet _document is of type org.w3c.dom.Document and _file is of type java.io.File.)

DOMImplementation domImplementation = _document.getImplementation();
DOMImplementationLS domImplementationLS 
  = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
LSSerializer serializer = domImplementationLS.createLSSerializer();
LSOutput lsOutput = domImplementationLS.createLSOutput();
OutputStream outputStream = new FileOutputStream(_file);
lsOutput.setByteStream(outputStream);
serializer.write(_document, lsOutput);
outputStream.close();


LSSerializer.setNewLine

http://download.oracle.com/javase/1,5.0/docs/guide/plugin/dom/org/w3c/dom/ls/LSSerializer.html#setNewLine(java.lang.String)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜