xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierpaolo Fumagalli <p...@apache.org>
Subject Re: How to deal with differences in DOM implementations?
Date Sat, 04 Mar 2000 02:26:05 GMT
Arnaud Le Hors wrote:
> 
> Pierpaolo Fumagalli wrote:
> >
> > > Eric Hodges wrote:
> > ...
> > > For instance, in JAXP, here's their example of how to create an
> > > element and add it to a document:
> > >
> > >  Document doc = db.newDocument ();
> > >  Element root = doc.createElement ("root");
> > >  Attr  tmp;
> > >  Writer  out = new OutputStreamWriter (System.out);
> > >
> > >  doc.appendChild (root);
> > >
> > > In Xerces, this produces an exception.  The last line must be changed
> > > to:
> > >
> > > doc.getDocumentElement().appendChild(root);
> >
> > This is wrong... And it must be a XERCES bug, even if in all the time I
> > worked w/ Xerces, I never had to do something like it... What version
> > are you using?
> 
> This is not wrong. Again, this is the result of Xerces strictly
> following the DOM Level 2 spec which says that createDocument() not only
> create the Document but also the root element. Given that a Document can
> only have one Element child it is only normal that trying to add any
> other raises an exception.

I can't find createDocument() anywhere... What I do is just, in the JAXP
implementation, when I am requested a new Document (calling
newDocument() in DocumentBuilder) is to return a new
org.apache.xerces.dom.DocumentImpl().

Aww... I found it in DOMImplementation. Yes. So, I believe you're right.
But what should I do from the implementation point of view? Create a new
document only when I receive the document root element?

> > > If the same change is applied to JAXP, getDocumentElement() returns a
> > > null, since the document is empty.
> >
> > That should be the right behaviour.
> 
> According to who?

According to how I ever did it on Xerces :) :) :) :) 

	Pier

-- 
--------------------------------------------------------------------
-          P              I              E              R          -
stable structure erected over water to allow the docking of seacraft
<mailto:pier@betaversion.org>    <http://www.betaversion.org/~pier/>
--------------------------------------------------------------------
- ApacheCON Y2K: Come to the official Apache developers conference -
-------------------- <http://www.apachecon.com> --------------------

Mime
View raw message