Java tutorial
import org.w3c.dom.Document; import org.apache.xerces.dom.DOMImplementation; import org.w3c.dom.Element; import org.apache.xml.serialize.XMLSerializer; import java.io.IOException; public class MainClass { public static void main(String args[]) throws IOException { Document dom = DOMImplementation.createDocument(null, null, null); Element root = dom.createElement("A"); Element child1 = dom.createElement("B"); child1.appendChild(dom.createTextNode("C")); child1.setAttribute("A", "a"); root.appendChild(child1); dom.appendChild(root); XMLSerializer serial = new XMLSerializer(System.out, null); serial.serialize(dom.getDocumentElement()); } }