How to remove encoding="UTF-8" standalone="no" from xml Document object in Java

VextoR picture VextoR · Sep 22, 2011 · Viewed 20.1k times · Source

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!

Answer

Erik Kaju picture Erik Kaju · Oct 28, 2011

Why do you need to remove an encoding? But..

doc.setXmlStandalone(true);

will erase standalone="no"