java编辑时怎么用dom来擦除doctype?
得到这个xml文件:
]>
test1
test1
test1
我的功能非常基本:
public static void EditStationName(int id, InputStream is, String path, String name) throws ParserConfigurationException, SAXException, IOException, TransformerFactoryConfigurationError, TransformerException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(is);
Element e = dom. getElementById(String.valueOf(id));
e.setTextContent(name);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
FileOutputStream fos = new FileOutputStream(path);
Result result = new StreamResult(fos);
Source source = new DOMSource(dom);
xformer.setOutputProperty(
OutputKeys.STANDALONE,"yes"
);
xformer.transform(source, result);
}
它的工作,但是doctype被删除!我只收到整个文档,但没有doctype部分,这对我很重要,因为它允许我通过id检索!
我们怎么能保持这个doctype?为什么会擦除它?
我尝试了许多解决方案与输出键例如或omImpl.createDocumentType,但没有一个这样工作…
谢谢 !