文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用jdom组装xml

使用jdom组装xml

时间:2011-02-20  来源:魔战

public class XMLWriter {
 public static void main(String args[])
 {
  Element root=new Element("selects");
  Element selectElt=new Element("select");
  Element idElt=new Element("id");
  idElt.addContent("1");
 
  Element valueElt=new Element("name");
  valueElt.addContent("吉林省");
  
  selectElt.addContent(idElt);
  selectElt.addContent(valueElt);
  
  root.addContent(selectElt);
  
  Document doc=new Document(rootElt);
  XMLOutputter out=new XMLOutputter();
  //设置输出的编码
  out.setFormat(Format.getCompactFormat().setEncoding("gb2312"));
  //输出字符串
  String xmlStr=out.outputString(doc);
     System.out.println(xmlStr);
    
     //保存在文件中
     out.output(doc,new FileOutputStream("c:/test.xml"));
 } 
}

相关阅读 更多 +
排行榜 更多 +
方块拼凑最新版 v1.0 安卓版

方块拼凑最新版 v1.0 安卓版

休闲益智 下载
方块拼凑最新版 v1.0 安卓版

方块拼凑最新版 v1.0 安卓版

休闲益智 下载
愤怒的小鸟爆破安卓版 v2.7.0 手机版

愤怒的小鸟爆破安卓版 v2.7.0 手机版

飞行射击 下载