dom4j例子Document
import java.io.FileWriter;
import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
public class DomTest {
??? /**
??? ?* @param args
??? ?* @throws IOException
??? ?*/
??? public static void main(String[] args) throws IOException {
??? ??? Document doc = DocumentHelper.createDocument();
??? ??? Element root = doc.addElement("wmc");
??? ??? Element header = root.addElement("head");
??? ??? Element title = header.addElement("title");
??? ??? Element body = root.addElement("body");
??? ??? body.addAttribute("height", "480px").addAttribute("width", "640px");
??? ??? FileWriter out = new FileWriter("e:/aa.xml");
??????? OutputFormat format = new OutputFormat("? ", true);
??????? XMLWriter writer = new XMLWriter(out, format);
??????? writer.write(doc.getRootElement());
??????? out.close();
??? }
}