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

     }

    魔由心生,有万境纵横,无一道清静,无量寿佛!
  • 相关阅读:
    全栈的苦逼和崛起
    Swift内部类调用外部类方法、属性的变通
    Assets.xcassets误删后的恢复
    UITableViewCell嵌套UITableView的正确姿势
    GPU Accelerated Computing with Python
    Windows 10创意者更新ISO发布!官方下载
    Amazing iOS Tips
    self-sizing cell的一个问题
    buf.swap32()
    buf.swap16()
  • 原文地址:https://www.cnblogs.com/qihuan/p/3699862.html
Copyright © 2020-2023  润新知