JAV书籍源程序《JAVA应用开发指南》代码 第2版源代码java3,第十一至二十章
源代码在线查看: domcreate.java
import org.apache.xerces.dom.DOMImplementation;
import org.w3c.dom.*;
public class DOMCreate {
public static void main(String[ ] args) {
Document dom=DOMImplementation.createDocument(null,null,null);
Element root=dom.createElement("root");
Element child1=dom.createElement("child1");
child1.appendChile(dom.creatTextNode ("This is child1"));
child1.setAttribute("value","Java2");
Element child2=dom.createElement("child2");
child1.appendChile(dom.creatTextNode ("This is child2"));
child1.setAttribute("value","XML");
root.appendChild(child1);
root.appendChild(child2);
dom.appendChild(root);
XMLSerializer serial=new XMLSerializer(System.out,null);
serial.serialize(dom.getDocumentElement());
}
}