码迷,mamicode.com
首页 > 其他好文 > 详细

XML 存储文档

时间:2014-07-22 23:15:52      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:java   os   io   re   c   ar   

package com.kpsh.myself;

import java.io.File;
import java.io.FileWriter;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

public class ParseXML {
 
 public static void main(String[] args) {
  createXMLFile();
 }

 public static void createXMLFile() {
  Document document = DocumentHelper.createDocument();
  Element booksElement = document.addElement("Student");

  Element bookElement = booksElement.addElement("book");
  bookElement.addAttribute("show", "Name");
  Element titleElement = bookElement.addElement("title");
  titleElement.setText("the new stduent");
  
  bookElement = booksElement.addElement("book");
  bookElement.addAttribute("show", "Num");
  titleElement = bookElement.addElement("title");
  titleElement.setText("his name");
  
  bookElement = booksElement.addElement("book");
  bookElement.addAttribute("show", "Address");
  titleElement = bookElement.addElement("title");
  titleElement.setText("上海");
  
  bookElement = booksElement.addElement("book");
  bookElement.addAttribute("show", "Tel");
  titleElement = bookElement.addElement("title");
  titleElement.setText("12345678");
  
  Element ownerElement = booksElement.addElement("owner");
  ownerElement.setText("qh");
  try {
   XMLWriter writer = new XMLWriter(new FileWriter(new File("e://output.xml")));
   writer.write(document);
   writer.close();
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }

 }

XML 存储文档,码迷,mamicode.com

XML 存储文档

标签:java   os   io   re   c   ar   

原文地址:http://www.cnblogs.com/qihuan/p/3699862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!