您可以在Java中使用JDOM库。将标签定义为Element对象,使用document
Class记录元素,并使用SAXBuilder构建xml文件。试试这个例子:
//Root ElementElement root=new Element("CONFIGURATION");document doc=new document();//Element 1Element child1=new Element("BROWSER");//Element 1 Contentchild1.addContent("chrome");//Element 2Element child2=new Element("base");//Element 2 Contentchild2.addContent("http:fut");//Element 3Element child3=new Element("EMPLOYEE");//Element 3 --> In this case this element has another element with Contentchild3.addContent(new Element("EMP_NAME").addContent("Anhorn, Irene"));//Add it in the root Elementroot.addContent(child1);root.addContent(child2);root.addContent(child3);//Define root element like rootdoc.setRootElement(root);//Create the XMLXMLOutputter outter=new XMLOutputter();outter.setFormat(Format.getPrettyFormat());outter.output(doc, new FileWriter(new File("myxml.xml")));


