XML文件生成——借助JDOM
2014-12-08 17:48
344 查看
import java.io.* ; import org.jdom.* ; import org.jdom.output.* ; public class DOMDemo { public static void main(String args[]) throws Exception { Element addresslist = new Element("addresslist") ; Element linkman = new Element("linkman") ; Element name = new Element("name") ; Element email = new Element("email") ; Attribute id = new Attribute("id","lxh") ; Document doc = new Document(addresslist) ; // 定义Document对象 name.setText("李兴华") ; name.setAttribute(id) ; // 将属性设置到元素之中 email.setText("mldnqa@163.com") ; linkman.addContent(name) ; // 设置关系 linkman.addContent(email) ; addresslist.addContent(linkman) ; XMLOutputter out = new XMLOutputter() ; out.setFormat(out.getFormat().setEncoding("GBK")) ; // 表示的是设置编码 out.output(doc,new FileOutputStream(new File("D:" + File.separator + "address.xml"))) ; } }
要求在工程中引入jdom.jar
相关文章推荐
- jdom生成xml文件
- Jdom生成xml文件
- jdom生成xml文件
- 如何借助DOM生成XML文件
- java中使用jdom生成百度新闻抓取的xml文件
- JDOM生成XML文件
- 使用JDOM生成xml文件
- Jdom解析、生成XML文件
- 【java】jdom生成xml文件
- 使用JDOM生成XML文件
- 用Trewview生成树:利用xml文件生成树结点
- 用Trewview生成树:利用xml文件生成树结点
- 遍历该文件夹下的所有文件并生成xml树
- 能否直接使用hbm.xml文件来生成数据结构呢?
- 在NetBeans5.0中使用xdoclet生成hibernate的*.hbm.xml文件
- 基于模板和XML在BS结构应用中生成word文件
- 用JDOM建立XML文件
- 包含DataSet类的XML架构怎么不自动生成CS文件了?(Fix一个小问题)
- 如何使用XCodeFactory自动生成XML配置文件和对应的解析类?
- [C#]包含DataSet类的XML架构怎么不自动生成CS文件了(XSD和CS文件不能合并)