org.w3c.dom.Document(标准java类库)
和
org.jdom.Document(JDOM9)都可以创建xml
并能输出。
和
org.jdom.Document(JDOM9)都可以创建xml
并能输出。
解决方案 »
- jar包 javax.resource.spi
- struts1.2源代码如何打成JAR包
- Spring问题,麻烦高手出手
- Hibernate 转换Set问题,在线等,急
- webserver 获取客户端ip
- tomcat org.apache.coyote.tomcat4.CoyoteConnector错误
- 多对一关系中actionForm的中的集合属性类与页面显示问题(在线等,解决了,立马给分)
- 我用jb2005+jboss3.2.4,试一下 message driver bean .部署不成功,紧呀!
- 写ejb,用xdoclet无法生成文件
- maven项目间依赖问题
- Zez、大家都来帮我看看,还没解决呢!?!??!?!?
- struts的actionform校验是在客户端还是服务端?
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
import org.apache.xml.serialize.XMLSerializer;
import java.io.IOException;
public class DomCreateExample{
public static void main(String args[])throws IOException{
Document dom=DOMImplementation.createDocument(null,null,null);
Element root=dom.createElement("games");
Element child1=dom.createElement("game");
root.appendChild(child1);
dom.appendChild(root);
child1.setAttribute("genre","rpg");
child1.appendChild(dom.createTextNode("Final Fantasy VII"));
XMLSerializer serial=new XMLSerializer(System.out,null);
serial.serialize(dom.getDocumentElement());
}
}
import org.jdom.*;
import org.jdom.output.XMLOutputter;public class HelloJDOM { public static void main(String[] args) { Element root = new Element("GREETING"); root.addChild("Hello JDOM!"); Document doc = new Document(root); // At this point the document only exists in memory.
// We still need to serialize it
XMLOutputter output = new XMLOutputter();
try {
output.output(doc, System.out);
}
catch (Exception e) {
System.err.println(e);
} }}