xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott_B...@lotus.com
Subject Re: Potential Xerces regression (bug# 933)
Date Tue, 13 Mar 2001 02:04:35 GMT

> JAXP 1.1, which is based on DOM Level 2, exposes a new method to create
> a DOM Document object to conform to DOM Level 2.  This is the preferred
> method to create a DOM Level 2 tree:
>
> DocumentBuilderFactory dbf = new DocumentBuilderFactory();
> dbf.setNamespaceAware(true);  // needed b/c default value is false
> DocumentBuilder db = dbf.newDocumentBuilder();
> DOMImplementation di = db.getDOMImplementation();  // W3C DOM Impl
> DocumentType dt = di.createDocumentType("pref:root", pubID, sysId);
> Document doc = createDocument("http://someuri", "pref:root", dt);

Edwin, this will not work for XSLT processing with JAXP 1.1.  People want
to create a Document node and have it populated by the XSLT processor.  In
order to support this we will have to change
javax.xml.transform.dom.DOMResult to hold a DOMImplementation that can be
passed in, so that Xalan can create the document node when an element node
is created (besides the change in JAXP, this is a fair amount of work in
Xalan, because this non-node will have to be passed through the entire
processing flow).  God, I wish this had been caught 3 months ago.  Perhaps
we can make that change for JAXP 1.2 or 1.1.1.  But, in any case, the
Javadoc does not seem to deprecate DocumentBuilderImpl#newDocument() that I
can see, so there's nothing to say it's "not preferred".  This is a
flat-out mismatch with DOM2.

I think that the near term solution to this is that it be documented that
DocumentBuilder#newDocument() can throw a not supported exception for some
DOM implementations, and precisely document that the Document returned is
in a temporarily invalid state that does not match any state recognized by
the DOM.

-scott




                                                                                         
                          
                    Edwin Goei                                                           
                          
                    <Edwin.Goei@en        To:                                         
                             
                    g.sun.com>            cc:     "xerces-j-dev@xml.apache.org" <xerces-j-dev@xml.apache.org>,
     
                                          "general@xml.apache.org" <general@xml.apache.org>,
(bcc: Scott            
                    03/12/2001            Boag/CAM/Lotus)                                
                          
                    06:08 PM              Subject:     Re: Potential Xerces regression (bug#
933)                   
                    Please respond                                                       
                          
                    to general                                                           
                          
                                                                                         
                          
                                                                                         
                          




Scott_Boag@lotus.com wrote:
>
> ========
> The other problem is "DOM006 Hierarchy request error" when outputting to
a
> DOM.  For some very strange reason someone decided that
> DocumentBuilder#newDocument() should add an element named "root" to the
> Document it creates.  Then, when Xalan goes to add the first element out
of
> the transform to the Document element, you predictable get "DOM006
> Hierarchy request error". In a unit test I do:
>
>         DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
>         Node xmlDoc = docBuilder.parse(new InputSource("foo.xml"));
>         org.w3c.dom.Document outNode = docBuilder.newDocument();
>         transformer.transform(new DOMSource(xmlDoc, "foo.xml"),
>                               new DOMResult(outNode));
>
> In Xerces 1.2.3 and Xerces 1.3.0, DocumentBuilderImpl#newDocument()
> [version 1.2] was (properly, I think) implemented as:
>
>     public Document newDocument() {
>         return(new org.apache.xerces.dom.DocumentImpl());
>     }
>
> In DocumentBuilderImpl#newDocument() [version 1.3] and on this is
> implemented as:
>
> DocumentBuilderImpl#newDocument() is implemented as:
>     public Document newDocument() {
>         DOMImplementation di = getDOMImplementation();
>         // XXX What should the root element be named???
>         String qName = "root";
>         DocumentType docType = di.createDocumentType(qName, null, null);
>         return di.createDocument(null, qName, docType);
>     }

I'll take responsibility for this bug.  The real problem, though, is
that DocumentBuilder.newDocument() was part of JAXP 1.0 which was based
on DOM Level 1 and so it had to be carried over to JAXP 1.1.  I was in a
hurry when implementing this method which should be deprecated since DOM
Level 2 came out.  Still, it should work for backwards compatibility, so
I'll check in a fix.

JAXP 1.1, which is based on DOM Level 2, exposes a new method to create
a DOM Document object to conform to DOM Level 2.  This is the preferred
method to create a DOM Level 2 tree:

DocumentBuilderFactory dbf = new DocumentBuilderFactory();
dbf.setNamespaceAware(true);  // needed b/c default value is false
DocumentBuilder db = dbf.newDocumentBuilder();
DOMImplementation di = db.getDOMImplementation();  // W3C DOM Impl
DocumentType dt = di.createDocumentType("pref:root", pubID, sysId);
Document doc = createDocument("http://someuri", "pref:root", dt);

Substitute appropriate values of the root node qname "pref:root" and
uri.

-Edwin

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org






---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message