CreateNewXML

来源:互联网 发布:电力数据通信网 编辑:程序博客网 时间:2024/05/17 01:19
package com.dom4j;import java.io.FileOutputStream;import java.io.IOException;import org.dom4j.Document;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.io.XMLWriter;public class CreateNewXML {public static void main(String[] args) throws IOException {Document docu = DocumentHelper.createDocument();Element root = docu.addElement("root");root.addElement("child").addElement("child1").setText("child1");root.element("child").addAttribute("gender", "boy");XMLWriter writer = new XMLWriter(new FileOutputStream("src/Demo.xml"));writer.write(docu);writer.close();} }

0 0
原创粉丝点击