对xml进行读操作:[url]http://cheney-mydream.iteye.com/admin/blogs/403212[/url]
接着上一次《java 操作xml 文件 <一>读取》的来
构建一个xml文件
接着上一次《java 操作xml 文件 <一>读取》的来
构建一个xml文件
public void testWrite(){
// 创建相关节点
Element root = new Element("person");
Element name = new Element("name");
name.addContent("张三");
Element age = new Element("age");
age.addContent("24");
// 把子节点加到父节点下
root.addContent(name);
root.addContent(age);
// 创建document对象
Document doc = new Document(root);
// 输出创建好的xml文件
XMLOutputter out = new XMLOutputter();
try {
out.output(doc, new FileOutputStream("c:/person.xml"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
本文介绍了一个使用Java编程语言创建XML文件的方法。通过实例演示了如何构建XML文档的基本结构,包括根节点、子节点及其内容。

被折叠的 条评论
为什么被折叠?



