Java tutorial
//package com.java2s; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; public class Main { private static final ThreadLocal<DocumentBuilderFactory> documentBuilderFactory = new ThreadLocal<DocumentBuilderFactory>() { protected DocumentBuilderFactory initialValue() { return DocumentBuilderFactory.newInstance(); }; }; /** * Create an empty XML document for building up a DOM tree. * @return the document */ public static Document createEmptyDocument() { try { DocumentBuilder documentBuilder = documentBuilderFactory.get().newDocumentBuilder(); Document document = documentBuilder.newDocument(); return document; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } } }