DocumentBuilder.parse returns DeferredDocumentImpl???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • edwinek

    DocumentBuilder.parse returns DeferredDocumentImpl???

    Hi,

    According to the API specification,
    javax.xml.parse rs.DocumentBuil der.parse should return an
    org.w3c.dom.Doc ument. However, when I use the following code:

    DocumentBuilder Factory factory = DocumentBuilder Factory.newInst ance();
    factory.setVali dating(false);
    factory.setName spaceAware(fals e);
    DocumentBuilder builder = factory.newDocu mentBuilder();
    ByteArrayInputS tream xmlIs = new
    ByteArrayInputS tream(polisLijs t.getBytes());
    Object parseReturn = builder.parse(x mlIs);
    System.out.prin tln("######## ["+parseReturn.g etClass().getNa me()+"]
    ######");
    Document xmlDoc = (Document) parseReturn;

    the println prints:

    ######## [org.apache.xerc es.dom.Deferred DocumentImpl] ######

    and the final statement gives an exception:

    [java.lang.Class CastException]
    [org.apache.xerc es.dom.Deferred DocumentImpl]
    stack-trace=[java.lang.Class CastException: ...

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

    Regards,
    Edwin
  • Ingo Pakleppa

    #2
    Re: DocumentBuilder .parse returns DeferredDocumen tImpl???

    org.w3c.dom.Doc ument is an interface. While I haven't checked out
    DeferredDocumen tImpl, 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.Doc ument xmlDoc = (org.w3c.dom.Do cument)parseRet urn;

    On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
    [color=blue]
    > Hi,
    >
    > According to the API specification,
    > javax.xml.parse rs.DocumentBuil der.parse should return an
    > org.w3c.dom.Doc ument. However, when I use the following code:
    >
    > DocumentBuilder Factory factory = DocumentBuilder Factory.newInst ance();
    > factory.setVali dating(false);
    > factory.setName spaceAware(fals e);
    > DocumentBuilder builder = factory.newDocu mentBuilder();
    > ByteArrayInputS tream xmlIs = new
    > ByteArrayInputS tream(polisLijs t.getBytes()); Object parseReturn =
    > builder.parse(x mlIs); System.out.prin tln("########
    > ["+parseReturn.g etClass().getNa me()+"] ######");
    > Document xmlDoc = (Document) parseReturn;
    >
    > the println prints:
    >
    > ######## [org.apache.xerc es.dom.Deferred DocumentImpl] ######
    >
    > and the final statement gives an exception:
    >
    > [java.lang.Class CastException]
    > [org.apache.xerc es.dom.Deferred DocumentImpl]
    > stack-trace=[java.lang.Class CastException: ...
    >
    > Why do I get an DeferredDocumen tImpl when I should get a Document? Am I
    > doing something wrong? Or else: how do I create a Document from this
    > mysterious DeferredDocumen tImpl?
    >
    > Regards,
    > Edwin[/color]

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

    Comment

    • edwinek

      #3
      Re: DocumentBuilder .parse returns DeferredDocumen tImpl???

      No, that wasn't it. I tried, but get the same exception.

      "Ingo Pakleppa" <ingo-newsgroups@kkea ne.com> wrote in message news:<pan.2003. 06.24.23.12.50. 110682@kkeane.c om>...[color=blue]
      > org.w3c.dom.Doc ument is an interface. While I haven't checked out
      > DeferredDocumen tImpl, 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.Doc ument xmlDoc = (org.w3c.dom.Do cument)parseRet urn;
      >
      > On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
      >[color=green]
      > > Hi,
      > >
      > > According to the API specification,
      > > javax.xml.parse rs.DocumentBuil der.parse should return an
      > > org.w3c.dom.Doc ument. However, when I use the following code:
      > >
      > > DocumentBuilder Factory factory = DocumentBuilder Factory.newInst ance();
      > > factory.setVali dating(false);
      > > factory.setName spaceAware(fals e);
      > > DocumentBuilder builder = factory.newDocu mentBuilder();
      > > ByteArrayInputS tream xmlIs = new
      > > ByteArrayInputS tream(polisLijs t.getBytes()); Object parseReturn =
      > > builder.parse(x mlIs); System.out.prin tln("########
      > > ["+parseReturn.g etClass().getNa me()+"] ######");
      > > Document xmlDoc = (Document) parseReturn;
      > >
      > > the println prints:
      > >
      > > ######## [org.apache.xerc es.dom.Deferred DocumentImpl] ######
      > >
      > > and the final statement gives an exception:
      > >
      > > [java.lang.Class CastException]
      > > [org.apache.xerc es.dom.Deferred DocumentImpl]
      > > stack-trace=[java.lang.Class CastException: ...
      > >
      > > Why do I get an DeferredDocumen tImpl when I should get a Document? Am I
      > > doing something wrong? Or else: how do I create a Document from this
      > > mysterious DeferredDocumen tImpl?
      > >
      > > Regards,
      > > Edwin[/color][/color]

      Comment

      • Ingo Pakleppa

        #4
        Re: DocumentBuilder .parse returns DeferredDocumen tImpl???

        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.getClas s().getMethods( ) )? Can you use reflection to find out all
        the base classes and interfaces from the DeferredDocumen tImpl class (hint:
        use getClass().getI nterfaces()).

        On Tue, 24 Jun 2003 22:59:07 -0700, edwinek wrote:
        [color=blue]
        > Sadly the DeferredDocumen tImpl 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" <ingo-newsgroups@kkea ne.com> wrote in message
        > news:<pan.2003. 06.24.23.12.50. 110682@kkeane.c om>...[color=green]
        >> org.w3c.dom.Doc ument is an interface. While I haven't checked out
        >> DeferredDocumen tImpl, 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.Doc ument xmlDoc = (org.w3c.dom.Do cument)parseRet urn;
        >>
        >> On Tue, 24 Jun 2003 05:11:49 -0700, edwinek wrote:
        >>[color=darkred]
        >> > Hi,
        >> >
        >> > According to the API specification,
        >> > javax.xml.parse rs.DocumentBuil der.parse should return an
        >> > org.w3c.dom.Doc ument. However, when I use the following code:
        >> >
        >> > DocumentBuilder Factory factory =
        >> > DocumentBuilder Factory.newInst ance(); factory.setVali dating(false);
        >> > factory.setName spaceAware(fals e);
        >> > DocumentBuilder builder = factory.newDocu mentBuilder();
        >> > ByteArrayInputS tream xmlIs = new
        >> > ByteArrayInputS tream(polisLijs t.getBytes()); Object parseReturn =
        >> > builder.parse(x mlIs); System.out.prin tln("########
        >> > ["+parseReturn.g etClass().getNa me()+"] ######"); Document xmlDoc =
        >> > (Document) parseReturn;
        >> >
        >> > the println prints:
        >> >
        >> > ######## [org.apache.xerc es.dom.Deferred DocumentImpl] ######
        >> >
        >> > and the final statement gives an exception:
        >> >
        >> > [java.lang.Class CastException]
        >> > [org.apache.xerc es.dom.Deferred DocumentImpl]
        >> > stack-trace=[java.lang.Class CastException: ...
        >> >
        >> > Why do I get an DeferredDocumen tImpl when I should get a Document? Am
        >> > I doing something wrong? Or else: how do I create a Document from
        >> > this mysterious DeferredDocumen tImpl?
        >> >
        >> > Regards,
        >> > Edwin[/color][/color][/color]

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

        Comment

        Working...