zoukankan      html  css  js  c++  java
  • dom4j Document的基本操作

    public void BaseOperation(){


      //创建一个document
      Document document=DocumentHelper.createDocument();


      //创建根结点
      Element root=document.addElement("root");


      //为根结点添加一个book节点
      Element book1=root.addElement("book");


      //为book1添加属性type
      book1.addAttribute("type","science");


      //为book1添加name子节点
      Element name1=book1.addElement("Name");


      //并设置其name为"Java"
      name1.setText("Java");


      //为book1创建一个price节点,并设其价格为100
      book1.addElement("price").setText("100");
      
      //为根结点添加第二个book节点,并设置该book节点的type属性
      Element book2=root.addElement("book").addAttribute("type","science");


      //为book1添加name子节点
      Element name2=book2.addElement("Name");


      //并设置其name为"Oracle"
      name2.setText("Oracle");


      //为book1创建一个price节点,并设其价格为200
      book2.addElement("price").setText("200");
      
      //输出xml
      System.out.println(document.asXML());
     }

  • 相关阅读:
    赋值运算符重载
    拷贝构造函数
    sizeof与strlen
    C++函数参数为引用或指针
    Largest Rectangle in Histogram
    二极管作用
    yzoj P1948 取数字问题
    NOIP 2016 愤怒的小鸟 题解
    NOIP 2016 蚯蚓 题解
    NOIP 2016 组合数问题 题解
  • 原文地址:https://www.cnblogs.com/yinghao/p/4794018.html
Copyright © 2011-2022 走看看