使用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. uva 10673 Play with Floor and Ceil

    Problem APlay with Floor and CeilInput: standard inputOutput: standard outputTime Limit: 1 second Th ...

  2. wpfのpack协议

    当引用的资源需要做成dll时,要用此协议 协议:pack://      授权:有两种.一种用于访问编译时已经知道的文件,用application:///.一种用于访问编译时不知道.运行时才知道的文件 ...

  3. Form1是父,form2是子,2的出现(覆盖在1的上面)不耽误1的操作

    //在form1的点击事件中 form2 f2=new form2(); f2.owner=this;//很重要 f2.show();

  4. AfterEffects 关键帧辅助功能

    http://www.cocoachina.com/design/20160121/15073.html 标准缓动曲线查询网址:http://easings.net/zh-cn

  5. nginx fastcgi 超时问题解决记录

    在网站后台导数据时,出现超时的情况.经过网上查找资料和试验 主要在下面几个配置的限制 1.php配置 第一种:set_time_limit(0); 永不过期 第二种: php.ini   max_ex ...

  6. BZOJ 1042 硬币购物(完全背包+DP)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1042 题意:给出四种面值的硬币c1,c2,c3,c4.n个询问.每次询问用d1.d2.d ...

  7. Creating Object Library OLB in Oracle D2k Form

    With following steps you can create Object Library (OLB) in Oracle D2k Forms.Step - 1Create a form i ...

  8. 统计fastq文件中读段的数量

    mycount=`cat SRR108114_new_1.fastq | wc -l` echo 'Number of clean reads, SRR108114_new_1.fastq: '$(( ...

  9. hdu 5925 Coconuts 离散化+dfs

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...

  10. CSS笔记(十)position属性与定位

    参考:http://www.w3school.com.cn/cssref/pr_class_position.asp position属性规定了元素的定位类型.任何元素都可定位,其中,绝对或固定元素会 ...