dom4j写xml 请教高手!

来源:百度知道 编辑:UC知道 时间:2024/06/14 13:11:39
我想用dom4j 写个xml文件
xml 文件的格式是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<graph caption="中文" xAxisName="Month" yAxisName="Units" decimalPrecision="0" formatNumberScale="0">
<set name="Jan" value="462" color="AFD8F8" />
<set name="Feb" value="857" color="F6BD0F" />
<set name="Mar" value="671" color="8BBA00" />
<set name="Apr" value="494" color="FF8E46" />
<set name="May" value="761" color="008E8E" />
<set name="Jun" value="960" color="D64646" />
<set name="Jul" value="629" color="8E468E" />
<set name="Aug" value="622" color="588526" />

import java.io.*;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Document doc = DocumentHelper.createDocument();
//创建数据指令对象
//doc.addProcessingInstruction("xml-stylesheet", "type = 'text/xsl' href = 'students.xsl'");

//处理指令没有执行
//Element root = doc.addElement("students");

//创建根元素

Element root = DocumentHelper.createElement("graph");
root.addAttribute("caption", "chinese");
root.addAttribute("xAxisName","Month");
root.addAttribute("yAxisName","Units");
root.addAttribute("decimalPrecision","0&q