Question: ```
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

Answer: 
Add this

```
format.setOmitXMLDeclaration(true);

```

Example

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

```
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);

```