解析xml报classnotfound错误

使用dom4j解析XML时,要快速获取某个节点的数据,使用XPath是个不错的方法,dom4j的快速手册里也建议使

用这种方式,

方法是使用Document的selectNodes(String XPath)方法,

selectSingleNode(String XPath)

代码写法:

List<?> list = document.selectNodes("//books/book");

执行时却抛出以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:164)

这么好用的方法怎么能抛异常呢,一路跟踪过去看,竟然是“List l = doc.selectNodes("//COLS/COL1");”

这句报错,查了一下才知道,不光要有dom4j这个包,还要有jaxen 包:<jaxen-1.1-beta-6.jar>,这

应该是dom4j的基础包,在dom4j的zip包的lib目录里可以找到。即使用这个方法需要以下两个包:

dom4j-1.6.1.jar
jaxen-1.1.jar

原文地址:https://www.cnblogs.com/lgm1999/p/5150577.html