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
but I need to remove the xml declaration from the output how can I do that
解决方案
Note that removing the header is valid in XML 1.0, but you lose character encoding data (amongst other things) which can be very important.