您的位置:首页 > 其它

xml

2015-07-29 16:05 253 查看
用jdom写xml文件

public
class App

{

public
static
void 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();

}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: