This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java XPath exception  RSS feed

 
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
Posts: 20895
81
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
Boost this thread!