通过 JDOM 方式生成 XML 文档
2015-01-15 14:31
351 查看
1.引入jdom jar包
2.代码
3.结果
2.代码
Element ele = new Element("tree"); ele.setAttribute("id","0"); Document document = new Document(ele); Element e1 = new Element("name"); e1.setText("名称"); ele.addContent(e1); // Format format = Format.getCompactFormat();//xml格式 Format format = Format.getPrettyFormat();//xml格式 // format.setIndent("");//设置换行,getPrettyFormat不用设 format.setEncoding("GBK"); XMLOutputter outputter = new XMLOutputter(format); try { outputter.output(document, new FileOutputStream(new File("jdomTest.xml"))); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
3.结果
<?xml version="1.0" encoding="GBK"?> <tree id="0"> <name>名称</name> </tree>
相关文章推荐
- 通过 SAX 方式生成 XML 文档
- 通过 DOM 方式生成 XML 文档
- 通过 DOM4J 方式生成 XML 文档
- JDom解析和生成XML文档
- 解析xml——采用Jdom与dom4J方式写入xml文档
- 通过代码XML注释与Sandcastle生成SDK文档(进阶篇)
- JDom解析和生成XML文档
- 解析XML文档方式之三:jdom方式
- Java 生成 XML 文档|JDOM
- java 解析xml文档---通过XmlPullParser解析方式
- xml通过schema方式的文档定义xsd,及使用示例
- Java中通过DOM方式提取出XML文档中的内容
- JDom解析和生成XML文档
- java操作xml文档(三) JDOM方式
- java的xml学习[JDOM方式解析XML文档]
- 利用JAXB通过XML模式生成XML文档
- 解析xml——采用Jdom与dom4J方式读xml文档
- 使用jdom生成xml文档
- 利用 JAXB 通过 XML 模式生成 XML 文档
- xml解析3:使用jdom框架进行对xml文档生成和读写解析