package com.test;
import java.io.FileWriter;
import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.io.File;
import java.io.FileWriter;
public class TestDom4j {
public static void main(String[] args) {
try {
Document document = DocumentHelper.createDocument();
document.addComment("create by luodada");
Element company = document.addElement("company");
Element department = company.addElement("department");
Element employee = department.addElement("employee");
company.addAttribute("companyID", "007");
department.addAttribute("deptName", "Sale");
department.addAttribute("count", "20");
employee.addAttribute("name", "kobe");
employee.addAttribute("age", "31");
File file = new File("c:/dom4j.xml");
FileWriter fw = new FileWriter(file);
document.write(fw);
fw.close();
System.out.println("Over......");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}