Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java XPath exception

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JDK 1.5, try to parse a xml file . But I always get an exception
java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMNodeList cannot be cast to org.apache.xpath.NodeSet

Please help.



The xml file is
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Apparently this call to xPath.evaluate does not return a NoteSet reference, but a DTMNodeList instead. And that does not extend or implement NoteSet; it does implement (indirectly) org.w3c.dom.NodeList.

And unlike the name XPathConstants.NODESET implies, it returns a NodeList, not a NodeSet.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:And unlike the name XPathConstants.NODESET implies, it returns a NodeList, not a NodeSet.


Thanks, I resolved it, I switched to (JDom + XPath). I don't understand why Sun JDK XPath is so hard and difficult to use.

Another question is, if we just want to extract a portion of XML, like my case, and I need to read, modify, delete one node, which API wil be better for this ?

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic