Outputting a DOM with XMLSerializer : xerces « XML « Java

Outputting a DOM with XMLSerializer


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.setAttribute("A", "a");



    XMLSerializer serial = new XMLSerializer(System.out, null);



Related examples in the same category

1.Walking a Document with DOM
2.Adding an Element with DOM
3.Adding an Attribute with DOM
4.Parsing XML with SAX
5.A simple example to show how to use the DOM API