Java tutorial
//package com.java2s; 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 synchronized Element createRootElement() { Element rootElement = null; try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = db.newDocument(); rootElement = doc.getDocumentElement(); } catch (Exception e) { e.printStackTrace(); } return rootElement; } public static synchronized Document newDocument() { Document doc = null; try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = db.newDocument(); } catch (Exception e) { e.printStackTrace(); } return doc; } }