xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edwin Goei <Edwin.G...@eng.sun.com>
Subject Re: Potential Xerces regression (bug# 933)
Date Mon, 12 Mar 2001 23:08:41 GMT
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


Mime
View raw message