import org.jdom.*;
import org.jdom.output.*;
import java.io.*;
import java.util.*;public class JdomDemo{

public static void main(String[] args){

Element root = new Element("root");
Document doc = new Document(root);
Element rot = new Element("rot");
rot.setAttribute(new Attribute("id","id"));
Element rogt = new Element("rot");
rogt.setAttribute(new Attribute("id","2"));
Element name=new Element("Node");
name.setAttribute(new Attribute("href","20"));
rogt.addContent(name);
root.addContent(rogt); try
{
String ident="  "; //子元素缩进两个空格
boolean isNew = true; //元素间有空行
String cset="gb2312"; //编码
XMLOutputter outer=new XMLOutputter(ident,isNew ,cset); outer.output(doc,new FileOutputStream("i:\\myxml.xml"));
file = null;
outer = null;
}
catch(IOException e){
e.printStackTrace();
} }

}