Use java to delete XML declarations from the generated XML document

String root = "RdbTunnels";
String root = "RdbTunnels";
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement(root);
document.appendChild(rootElement);   

OutputFormat format = new OutputFormat(document);
format.setIndenting(true);


XMLSerializer serializer = new XMLSerializer(System.out,format);
serializer.serialize(document);

The results are as follows

<?xml version="1.0" encoding="UTF-8"?>
<RdbTunnels/>

But I need to remove the XML declaration from the output. What should I do?

Solution

Has transformer seen outputkeys? Specific omit_ XML_ DECLARATION.

Note that deleting headers is valid in XML 1.0, but you are missing character encoded data (among other things), which can be very important

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>