I want to create XML in Java.
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
but Java automatically creates declaration like this
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
How can I remove encoding="UTF-8" standalone="no"
so it will be
<?xml version="1.0"?>
Thanks!
Why do you need to remove an encoding? But..
doc.setXmlStandalone(true);
will erase standalone="no"
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
This would resolve your issue, verified at JDK 6
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