Here you can find the source of newDocument(String rootName)
public final static Document newDocument(String rootName) throws ParserConfigurationException
//package com.java2s; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public final static Document newDocument(String rootName) throws ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document xml = db.newDocument(); Node root = xml.createElement(rootName); Attr a = xml.createAttribute("version"); a.setValue("0.6"); root.getAttributes().setNamedItem(a); a = xml.createAttribute("encoding"); a.setValue("UTF-8"); root.getAttributes().setNamedItem(a); xml.appendChild(root);//from w w w .j a va 2 s.com return xml; } }