JAva xmlファイルの作成
jdom.jar
package com.dragon.main;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.output.XMLOutputter;
public class TestXml {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(" ... ...");
try {
TestXml testXml = new TestXml();
System.out.println(" XXX.xml ...");
testXml.CreateXMLFile();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("D:/XXX.xml ");
}
/**
* XML
* @throws IOException
* @throws JDOMException
*/
public void CreateXMLFile() throws IOException, JDOMException {
//
Element root = new Element("dagl");
//
Document Doc = new Document(root);
// image;
Element elements = new Element("image");
// image id;
//elements.setAttribute("id", "" + i);
// user ;
// new Element("name") "name" ,setText("xuehui") "xuehui ;
//
//
//
Element element = new Element("id");
element.setText("6402000004001");//
elements.addContent(element);
//
//
elements.addContent(new Element("name").setText(" "));
//
elements.addContent(new Element("ywlx").setText("A"));
//
elements.addContent(new Element("zlzl").setText("A"));
//
elements.addContent(new Element("zlzl").setText("A"));
//
root.addContent(elements);
XMLOutputter XMLOut = new XMLOutputter();
// name
//FileOutputStream fileOutputStream = new FileOutputStream(name)
// user.xml ;
XMLOut.output(Doc, new FileOutputStream("D:/6402000004001.xml"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<dagl>
<image>
<id>6402000004001</id>
<name> </name>
<ywlx>A</ywlx>
<zlzl>A</zlzl>
<zlzl>A</zlzl>
</image>
</dagl>