首先下载JDOM.JAR加入的classpath中 package com.test.search; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.output.XMLOutputter; public class ToXML { public void BuildXMLDoc(List<SearchBean> list) throws IOException, JDOMException { //创建跟节点 Element root=new Element("search"); //将跟节点添加到文档中 Document document=new Document(root); for (int i = 0; i < list.size(); i++) { SearchBean bean=list.get(i); Element element=new Element("object"); element.addContent(new Element("URL").setText(bean.getUrl())); element.addContent(new Element("TITLE").setText(bean.getTitle())); element.addContent(new Element("DESCRIBE").setText(bean.getDiscribe())); element.addContent(new Element("INFO").setText(bean.getInfo())); root.addContent(element); } XMLOutputter out=new XMLOutputter(); out.output(document, new FileOutputStream("search.xml")); } /*public static void main(String[] args) { ToXML toXML=new ToXML(); }*/ } 生成完成,只是生成的xml文档的节点有点乱,不是树型的。