zoukankan      html  css  js  c++  java
  • XML 存储文档

    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();
      }
     }

     }

    魔由心生,有万境纵横,无一道清静,无量寿佛!
  • 相关阅读:
    Python第二弹--------类和对象
    Python第一弹--------初步了解Python
    Java标记接口
    CentOS7下的YUM源服务器搭建详解,过程写的很详细(转)
    CentOS7.0安装Nginx 1.10.0
    QT中C++与Html端通信例子
    QT基础:QMainWindow学习小结
    QT基础:QT 定时器学习
    QT3D场景快速绘制入门学习
    QT编译错误:cannot find file: *.pro
  • 原文地址:https://www.cnblogs.com/qihuan/p/3699862.html
Copyright © 2011-2022 走看看