import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class TestDom4jXpath {
public static void main(String[] args) throws Exception {
// 创建解析器
SAXReader saxReader = new SAXReader();
// 得到document
Document document = saxReader.read("src/day06/p1.xml");
// 使用selectNodes("//name")方法得到所有的name元素
List<Node> list = document.selectNodes("//name");
// 遍历list集合
for (Node node : list) {
// node是每一个name元素
String s = node.getText();
System.out.println(s);
}
}
}