File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java XPath exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java XPath exception" Watch "java XPath exception" New topic
Author

java XPath exception

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
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

Joined: Oct 27, 2005
Posts: 19693
    
  20


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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java XPath exception