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