参考文章
-------------
JDOM使用详解及实例
http://www.webdn.com/web_file/3sword/xml/0602016011/
用 JDOM 简化 XML 编程
http://www.ibm.com/developerworks/cn/java/j-jdom/
JDom使用详解
http://www.cn-java.com/www1/?action-viewnews-itemid-3569
用JDom轻松整合Java和XML
http://www.programfan.com/article/showarticle.asp?id=2859
入门实例
-------------
1. 到http://www.jdom.org/downloads/index.html下载JDOM1.1。
2. 编写JDOMXML.java。编译时需要在classpath中包含jdom.jar.
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
public class JDOMXML {
public String myString;
public void createDoc(){
Element root = new Element("tasks");
Document Doc = new Document(root);
Element elements = new Element("task");
elements.addContent(new Element("name").setText("first"));
elements.addContent(new Element("action").setText("open"));
root.addContent(elements);
elements = new Element("task");
elements.addContent(new Element("name").setText("second"));
elements.addContent(new Element("action").setText("close"));
root.addContent(elements);
XMLOutputter outp = new XMLOutputter();
myString = outp.outputString(Doc);
/* 还有好多种别的输出方法,可参考JDOM API */
}
public static void main(String[] args) {
JDOMXML jDomXML = new JDOMXML();
jDomXML.createDoc();
System.out.println(jDomXML.myString);
}
}