zoukankan      html  css  js  c++  java
  • 存入xml操作

     1         //存入数据库
     2         try {
     3             //解析xml
     4             SAXReader reader = new SAXReader();
     5             String path = this.getServletContext().getRealPath("WEB-INF/classes/users.xml");
     6             Document dom = reader.read(path);
     7             Element root = dom.getRootElement();
     8             //凭空创建userEle保存用户信息
     9             Element userEle = DocumentHelper.createElement("user");
    10             userEle.setAttributeValue("username", username);
    11             userEle.setAttributeValue("password", password);
    12             userEle.setAttributeValue("nickname", nickname);
    13             userEle.setAttributeValue("email", email);
    14             //挂载到根节点
    15             root.add(userEle);
    16             //更新xml
    17             XMLWriter wrtier = new XMLWriter(new FileOutputStream(path),OutputFormat.createPrettyPrint());
    18             wrtier.write(dom);
    19             wrtier.close();
    20         } catch (Exception e) {
    21             e.printStackTrace();
    22             throw new RuntimeException(e);
    23         }
    24     }
  • 相关阅读:
    H5图片上传、压缩
    数据库基本操作
    数组遍历
    CURL
    获取IP
    Memcached的实战笔记
    修bug总结 (基于java语言)
    java开发工作的总结
    多线程测试类
    可清除的单例对象获取类
  • 原文地址:https://www.cnblogs.com/pxffly/p/7462769.html
Copyright © 2011-2022 走看看