zoukankan      html  css  js  c++  java
  • Dom4j操作XML

    创建XML

    需要的jar包:dom4j.github.io

    // 创建document对象
    Document document = DocumentHelper.createDocument();
    // 根节点
    Element root = document.addElement("root");
    // 添加属性
    root.addAttribute("id", "root");
    // 添加子节点
    Element head =  root.addElement("head");
    Element body =  root.addElement("body");
    // 添加内容
    head.setText("hello world");
    body.setText("hello body");
    // 增加内容 ( 类似StringBuilder
    head.addText(",this is head");
    // 修改内容(再次set
    body.setText("body内容已修改");
    // 清除节点内容
    body.clearContent();
    // 删除节点
    root.remove(body);
    System.out.println(document.asXML());
    

    解析XML

    URL url = new URL("https://www.zhihu.com/rss");
    SAXReader reader = new SAXReader();
    Document document = reader.read(url);
    
  • 相关阅读:
    xutils 上传文件 ,暂时
    UIView.FRAMEWORK
    2016.11.7
    2016.11.6新阶段开始
    远程推送
    xcode8 导入 dylib
    bugly使用
    anelife
    心阶段
    新阶段
  • 原文地址:https://www.cnblogs.com/52liming/p/9536980.html
Copyright © 2011-2022 走看看