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);
gives the result as following
<?xml version="1.0" encoding="UTF-8"?>
<RdbTunnels/>
but I need to remove the xml declaration from the output how can I do that
Add this
format.setOmitXMLDeclaration(true);
Example
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
format.setOmitXMLDeclaration(true);
Have you seen OutputKeys
as used by Transformer
? Specifically OMIT_XML_DECLARATION
.
Note that removing the header is valid in XML 1.0, but you lose character encoding data (among other things) which can be very important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With