remove xml declaration from the generated xml document using java

By using the setOmitXMLDeclaration(true); method from the Format class. I'm not sure but I think it uses jDom lib.

Example (it will display the XML file without the XML declaration of the Document document)

XMLOutputter out= new XMLOutputter(Format.getCompactFormat().setOmitDeclaration(true));
out.output(document, System.out);

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.


Add this

format.setOmitXMLDeclaration(true);

Example

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