dom4j解析XML文件,通过属性查找节点,出现异常

dom4j解析文件时,通过某个属性查找节点,使用了selectNodes和selectSingleNodes方法

Element instance = root.element("book");
//参数:节点名[@属性名='属性值']
Node subject = instance.selectSingleNode("title[@value='test']");
运行时出现以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext
at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
at org.dom4j.tree.AbstractNode.selectSingleNode(AbstractNode.java:183)
at com.excel.test.WriteExcel.getRecordText(WriteExcel.java:113)
at com.excel.test.WriteExcel.getVoiceRecord(WriteExcel.java:86)
at com.excel.test.WriteExcel.main(WriteExcel.java:53)
Caused by: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
 
在网上找到解决办法:
需要使用加上jaxen包,这个包在dom4j的lib目录中可以找到。
参考:http://hi.baidu.com/vjame/item/042fe137cc948ebe124b1413

转载于:https://www.cnblogs.com/skyeyh/p/3708861.html

你可能感兴趣的:(dom4j解析XML文件,通过属性查找节点,出现异常)