使用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

解析xml报classnotfound错误的更多相关文章

  1. 【Maven】运行项目,报ClassNotFound错误

    我们在pom.xml中添加了那些依赖的jar后,一旦在代码中应用.当我们本地调试时,会报ClassNotFound错误,这是为什么?? 因为Tomcat不懂这些配置,你必须把Maven Depende ...

  2. DOM解析XML报错:Content is not allowed in prolog

    报错内容为: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. 网上所述总结来 ...

  3. 用dom4j解析xml 报java.lang.NoClassDefFoundError:org/jaxen/JaxenException

    转自:http://www.myexception.cn/java%20exception/95.html 源码如下: import java.io.File; import java.util.Li ...

  4. dom4j解析xml报错:Nested exception: org.xml.sax.SAXParseException: White space is required between the processing instruction target and data.

    采用dom4j方式解析string类型的xml xml:        String string="<?xmlversion=\"1.0\" encoding=\ ...

  5. dom4j解析xml报"文档中根元素后面的标记格式必须正确"

    今天,在写个批量启动报盘机的自动化应用,为了简化起见,将配置信息存储在xml中,格式如下: <?xml version="1.0" encoding="UTF-8& ...

  6. dom4j解析xml时报出文件提前结束

    在写javaweb小项目的时候,用dom4j解析xml报出如下错误: org.dom4j.DocumentException:Error    .......    Nested exception: ...

  7. Python读取xml报错解析--ExpatError: not well-formed (invalid token)

    xml文件内容如代码所示存入的名字为login.xml: <?xml version="1.0" encoding="utf-8"?> <in ...

  8. 解析xml字符串时报“前言中不允许有内容”错误。

    一,问题出现经过: j基于java语言webservic服务端接收客户端 传来的xml字符串用 解析时总报:org.dom4j.DocumentException: Error on line 1 o ...

  9. Received non-all-whitespace CHARACTERS or CDATA event in nextTag(). ,无法整齐打印验证错误。 解析XML文档出现的问题

    在启动keyCloak,想要在standAlone模式下切换数据库,修改standAlone.xml文件时. 在bin/目录下启动standAlone模式出现错误: 10:07:24,799 INFO ...

随机推荐

  1. 编写一个JAVA小程序取得IP地址

    在TCP/IP 互联网时,经常会需要查询自己主机的IP地址和www服务器的IP地址.虽然,我们可以使用IPCONFIG 和PING 进行IP地址查询,但是如果在应用程序或APPLET中使用此命令会破坏 ...

  2. MVC 中使用EF

    EF 1)简单查询 后台代码 using MvcApplication18.Models; using System; using System.Collections.Generic; using ...

  3. Java中HashMap遍历的两种方式

    Java中HashMap遍历的两种方式 转]Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml 第一种: ...

  4. PHP判断用户设备是否是移动设备

    摘自http://www.oschina.net/code/snippet_1432190_46913   <?php function isMobile() { // 如果有HTTP_X_WA ...

  5. 启动Print Spooler服务提示:"错误1068,依存服务或无法启动"

    本人windows8操作系统,从网上看到在运行中输入  sc config spooler depend= rpcss 即可,试了下果然有效.具体原因待了解.

  6. 关于三星A7屏幕锁已由管理员、加密政策,或证书存储禁用

    解决办法:设定-安全-清除证书-再返回锁定屏幕-把密码锁定-改为滑动.....

  7. BZOJ 2007 海拔(平面图最小割-最短路)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2007 题意:给出一个n*n的格子,那么顶点显然有(n+1)*(n+1)个.每两个相邻顶点 ...

  8. Android 程序打包和安装过程

    APP程序打包与安装的流程: APP的安装过程:

  9. spring引入实体类映射文件

    由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好  LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件:  mapp ...

  10. [c/c++]linux下使用c/c++操作mysql

    首先需要安装相应的库文件,直接apt-get就可以. sudo apt-get install libmysqlclient-dev 编译的时候,需要额外链接到这个库.如果是apt-get安装的话,那 ...