2.4 使用 xpath 对xml 进行解析

 1 public class Demo1 {
 2 
 3     /**
 4      * XPath提取XML文档数据
 5      * xpath很强大 用来提取xml文档数据非常方便
 6      * @throws Exception 
 7      */
 8     public static void main(String[] args) throws Exception {
 9         
10         SAXReader reader = new SAXReader(); 
11         Document document = reader.read("src/book.xml");
12         
13         //这个语句的作用:选出  所有的  作者节点  ,把第一个作为结果返回
14         Node node = document.selectSingleNode("//作者");   //  "//作者"  指的是 选出  所有的  作者节点
15         
16         String value = node.getText();
17         System.out.println(value);
18     }
19 
20 }
原文地址:https://www.cnblogs.com/xuzekun/p/7356166.html