xml

来源:互联网 发布:淘宝无线模板 编辑:程序博客网 时间:2024/06/03 05:36

用jdom写xml文件


publicclass App



{


publicstaticvoid main( String[] args )throws Exception



{


OutputStream out = new FileOutputStream("d:/customers.xml");


Document document = new Document();


Element root = new Element("customers");



document.setRootElement(root);


for(int i=0;i<10;i++){


Element ec = new Element("customer");


Element namee = new Element("cname");


namee.addContent("fiona"+i);


Element passworde = new Element("password");


passworde.addContent("123"+i);


Element birthe = new Element("birth");


birthe.addContent("1992-10-1"+i);



ec.addContent(namee);


ec.addContent(passworde);


ec.addContent(birthe);


root.addContent(ec);


}


XMLOutputter outputter = new XMLOutputter();



outputter.setFormat(Format.getPrettyFormat());


outputter.output(document, out);


out.close();


}


}



0 0