本书结合作者丰富的实践经验和深厚的理论基础
源代码在线查看: 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());
}
}