469,366 Members | 2,497 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

DocumentBuilder.parse returns DeferredDocumentImpl???

Hi,

According to the API specification,
javax.xml.parsers.DocumentBuilder.parse should return an
org.w3c.dom.Document. However, when I use the following code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream xmlIs = new
ByteArrayInputStream(polisLijst.getBytes());
Object parseReturn = builder.parse(xmlIs);
System.out.println("######## ["+parseReturn.getClass().getName()+"]
######");
Document xmlDoc = (Document) parseReturn;

the println prints:

######## [org.apache.xerces.dom.DeferredDocumentImpl] ######

and the final statement gives an exception:

[java.lang.ClassCastException]
[org.apache.xerces.dom.DeferredDocumentImpl]
stack-trace=[java.lang.ClassCastException: ...

Why do I get an DeferredDocumentImpl when I should get a Document? Am
I doing something wrong? Or else: how do I create a Document from this
mysterious DeferredDocumentImpl?

Regards,
Edwin
Jul 17 '05 #1
3 14888
org.w3c.dom.Document is an interface. While I haven't checked out
DeferredDocumentImpl, it most likely implements this interface.

My guess is that there is another class Document from a different package.
Try using the fully qualified class name:

org.w3c.dom.Document xmlDoc = (org.w3c.dom.Document)parseReturn;

On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
Hi,

According to the API specification,
javax.xml.parsers.DocumentBuilder.parse should return an
org.w3c.dom.Document. However, when I use the following code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream xmlIs = new
ByteArrayInputStream(polisLijst.getBytes()); Object parseReturn =
builder.parse(xmlIs); System.out.println("########
["+parseReturn.getClass().getName()+"] ######");
Document xmlDoc = (Document) parseReturn;

the println prints:

######## [org.apache.xerces.dom.DeferredDocumentImpl] ######

and the final statement gives an exception:

[java.lang.ClassCastException]
[org.apache.xerces.dom.DeferredDocumentImpl]
stack-trace=[java.lang.ClassCastException: ...

Why do I get an DeferredDocumentImpl when I should get a Document? Am I
doing something wrong? Or else: how do I create a Document from this
mysterious DeferredDocumentImpl?

Regards,
Edwin


--
Keep American Families united! Support H.R. 539 and H.R. 832
For more information, see http://www.kkeane.com/lobbyspousal-faq.shtml

Jul 17 '05 #2
No, that wasn't it. I tried, but get the same exception.

"Ingo Pakleppa" <in*************@kkeane.com> wrote in message news:<pa****************************@kkeane.com>.. .
org.w3c.dom.Document is an interface. While I haven't checked out
DeferredDocumentImpl, it most likely implements this interface.

My guess is that there is another class Document from a different package.
Try using the fully qualified class name:

org.w3c.dom.Document xmlDoc = (org.w3c.dom.Document)parseReturn;

On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
Hi,

According to the API specification,
javax.xml.parsers.DocumentBuilder.parse should return an
org.w3c.dom.Document. However, when I use the following code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream xmlIs = new
ByteArrayInputStream(polisLijst.getBytes()); Object parseReturn =
builder.parse(xmlIs); System.out.println("########
["+parseReturn.getClass().getName()+"] ######");
Document xmlDoc = (Document) parseReturn;

the println prints:

######## [org.apache.xerces.dom.DeferredDocumentImpl] ######

and the final statement gives an exception:

[java.lang.ClassCastException]
[org.apache.xerces.dom.DeferredDocumentImpl]
stack-trace=[java.lang.ClassCastException: ...

Why do I get an DeferredDocumentImpl when I should get a Document? Am I
doing something wrong? Or else: how do I create a Document from this
mysterious DeferredDocumentImpl?

Regards,
Edwin

Jul 17 '05 #3
That would be very strange indeed, because the compiler should have
complained about that when they developed the library. Can you use
reflection to get the prototype of parse from the builder class (use
builder.getClass().getMethods() )? Can you use reflection to find out all
the base classes and interfaces from the DeferredDocumentImpl class (hint:
use getClass().getInterfaces()).

On Tue, 24 Jun 2003 22:59:07 -0700, edwinek wrote:
Sadly the DeferredDocumentImpl class doesn't implement the Document
interface. There is no way to cast it to Document. So why does a method
that according to the API should return a Document return something
entirely different?

"Ingo Pakleppa" <in*************@kkeane.com> wrote in message
news:<pa****************************@kkeane.com>.. .
org.w3c.dom.Document is an interface. While I haven't checked out
DeferredDocumentImpl, it most likely implements this interface.

My guess is that there is another class Document from a different
package. Try using the fully qualified class name:

org.w3c.dom.Document xmlDoc = (org.w3c.dom.Document)parseReturn;

On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
> Hi,
>
> According to the API specification,
> javax.xml.parsers.DocumentBuilder.parse should return an
> org.w3c.dom.Document. However, when I use the following code:
>
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance(); factory.setValidating(false);
> factory.setNamespaceAware(false);
> DocumentBuilder builder = factory.newDocumentBuilder();
> ByteArrayInputStream xmlIs = new
> ByteArrayInputStream(polisLijst.getBytes()); Object parseReturn =
> builder.parse(xmlIs); System.out.println("########
> ["+parseReturn.getClass().getName()+"] ######"); Document xmlDoc =
> (Document) parseReturn;
>
> the println prints:
>
> ######## [org.apache.xerces.dom.DeferredDocumentImpl] ######
>
> and the final statement gives an exception:
>
> [java.lang.ClassCastException]
> [org.apache.xerces.dom.DeferredDocumentImpl]
> stack-trace=[java.lang.ClassCastException: ...
>
> Why do I get an DeferredDocumentImpl when I should get a Document? Am
> I doing something wrong? Or else: how do I create a Document from
> this mysterious DeferredDocumentImpl?
>
> Regards,
> Edwin


--
Keep American Families united! Support H.R. 539 and H.R. 832
For more information, see http://www.kkeane.com/lobbyspousal-faq.shtml

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dave Kuhlman | last post: by
9 posts views Thread by ThunderMusic | last post: by
3 posts views Thread by Jon Davis | last post: by
3 posts views Thread by GP | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
1 post views Thread by schaf | last post: by
4 posts views Thread by =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.