• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException with Document, DocumentTraversal

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am getting a ClassCastException with the code listed below.
The problem is with the line: "DocumentTraversal traversal=(DocumentTraversal) doc", where I get a java.lang.ClassCastException error.

A similar problem was brought up at Previous JavaRanch Topic - what am I doing wrong?and answered by someone with considerable authourity - however, as far as
I can tell Document to DocumentTraversal casting is permitted:

XML APIs Quick Reference
(under the DocumentTraversal section)

Also, most of this code (including the casting) is from the relatively authouritative ibm site:
Using a DOM NodeFilter

Code follows below:



Edit Comment: Added [ code ] [ / code ] tags, without the space.
[ November 02, 2004: Message edited by: Madhav Lakkapragada ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
psssstttt......you left out a key peice of info in that link that you
posted. From the DocumentTraversal section of the XML API link that you
posted -


In implementations that support the traversal API (which can be
determined by invoking the hasFeature("Traversal", "2.0" ) method in the
Document or DOMImplementation classes)
all objects that implement
Document also implement DocumentTraversal. That is, to create a
DocumentTraversal object, just cast a Document to DocumentTraversal.



So, I would change the code and invoke the hasFrature("Traversal", "2.0")
API and then see what type of results you get.

Please do let us know what you find.
Thanks.

- m
 
Jim Henessey
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Madhav Lakkapragada:
psssstttt......you left out a key peice of info in that link that you
posted. From the DocumentTraversal section of the XML API link that you
posted -



So, I would change the code and invoke the hasFrature("Traversal", "2.0")
API and then see what type of results you get.

Please do let us know what you find.
Thanks.

- m




Oh wow - thanks for catching that. That is the source of the problem - when I do a test, I get back that the feature doesn't exist. I'll look for options around this.

Thanks again for your help.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a hunch. Glad I could help.
Do keep posting.

- m
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic