参考:https://dom4j.github.io/
http://www.cnblogs.com/liuling/archive/2013/02/05/dom4jxml.html
常用api:
1.获取Document
对象,解析xml()
SAXReader reader = new SAXReader(); Document document = reader.read(url);
从文本解析的话,
File xmlFile = new File("C:\XX.xml")
Document document = reader.read(url);
2、获取root 元素
document.getRootElement()
3、选择某个节点下的元素 重点!!!!
document
.selectNodes(路径)
document
.selectNodes("/root/books/book")
需要引用jaxen.jar !!!
采用xpath查找需要引入jaxen-xx-xx.jar,否则会报java.lang.NoClassDefFoundError: org/jaxen/JaxenException异常。