在修改xml
文档之后,我已经将该文档写入了一个新文件。但是,在此xml
文件中,xml
声明后缺少换行符:
<?xml version="1.0" encoding="utf-8" standalone="no"><!DOCTYPE EMail SYSTEM "../src/email.dtd">
<Mail><Person>John</Person>
<Number>7</Number>
</Mail>
public void createDoc(File outputFile) throws FileNotFoundException, IOException, TransformerConfigurationException,
TransformerException, TransformerFactoryConfigurationError {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, this.dtdName);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(this.doc), new StreamResult(new OutputStreamWriter(new FileOutputStream(outputFile))));
}
为什么xml decl和doctype标记之间没有换行符?如果我使用记事本打开文件并想立即换行,则记事本会崩溃。那是Java的错误吗?