Java tutorial
//package com.java2s; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * Creates a new Element having the specified qualified name. The element * must be {@link Document#adoptNode(Node) adopted} when inserted into * another Document. * * @param qName A QName object. * @return An Element node (with a Document owner but no parent). */ public static Element createElement(QName qName) { Document doc = null; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Element elem = doc.createElementNS(qName.getNamespaceURI(), qName.getLocalPart()); return elem; } }