Here you can find the source of createDocument()
public static Document createDocument()
//package com.java2s; //License from project: Creative Commons License import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static Document createDocument() { Document doc = null;//from ww w .j a va 2s . c o m try { DocumentBuilderFactory docFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.newDocument(); Element element = doc.getDocumentElement(); // do i actually need to do this here? why? if (element != null) element.normalize(); } catch (Throwable t) { t.printStackTrace(); } return doc; } }