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();
} }
}
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();
} }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货