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

ClassCastException with Document, DocumentTraversal

Jim Henessey
Ranch Hand

Joined: Sep 13, 2003
Posts: 32
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 ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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

Joined: Sep 13, 2003
Posts: 32
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

Joined: Jun 03, 2000
Posts: 5040
Just a hunch. Glad I could help.
Do keep posting.

- m
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException with Document, DocumentTraversal