Here you can find the source of createDocument(Node node)
static public Document createDocument(Node node) throws Exception
//package com.java2s; //License from project: Open Source License import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMResult; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { static public Document createDocument(Node node) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);//from w w w. jav a 2 s . c o m Document doc = dbf.newDocumentBuilder().newDocument(); if (node != null) { Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(node), new DOMResult(doc)); } return doc; } }