1、读取:由xml转化
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
Document document = reader.read(new File(strFileName));
将xml文件读到Document中,这样
转String document.asXML();
获得根节点Element root = document.getRootElement();
获得各个元素的内容root.elementText("userid");
2、读取,由inputstream转化
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
Document document = reader.read(inputStream);
3、读取,由String转化
Document document = DocumentHelper.parseText(text);
4、创建
Document document = DocumentHelper.createDocument();
Element root = document.addElement("根节点名称");
转载于:https://blog.51cto.com/xiaoniudu/1300061