• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

java XPath exception

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic