Adding an Attribute with DOM : xerces « XML « Java






Adding an Attribute with DOM

 

import org.w3c.dom.Document;
import org.apache.xerces.dom.DOMImplementation;
import org.w3c.dom.Element;

public class MainClass {

  public static void main(String args[]) {
    Document dom = DOMImplementation.createDocument(null, null, null);
    Element root = dom.createElement("games");
    Element child1 = dom.createElement("game");
    root.appendChild(child1);
    child1.setAttribute("A", "a");
  }

}

 








Related examples in the same category

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