import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import javax.swing.JOptionPane;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class Test20 {
public static void main(String[] args) throws Exception { Document dom=DocumentHelper.createDocument();//創建xml文件 Element root=dom.addElement("url");//添加根元素,Xval Element data=root.addElement("data"); data.setText("淘寶"); Element licence=root.addElement("Licence"); licence.setText("免費軟件"); String xml=dom.asXML(); System.out.println(xml); File f=new File("d:/xml.xml"); PrintWriter pw=new PrintWriter(f); pw.write(xml); pw.close(); JOptionPane.showMessageDialog(null, "已生成xml文件,路徑為為d:/xml.xml"); }}
用的是dom4j,見附件,
Have Fun