You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Vl...@bmo.com on 2002/05/07 18:27:04 UTC

Re: how to modify DOCTYPE node in an existing document?

Elliotte Rusty Harold <el...@metalab.unc.edu>
05/06/2002 07:23 PM
Please respond to xerces-j-user

 
        To:     xerces-j-user <xe...@xml.apache.org>
        cc: 
        Subject:        Re: how to modify DOCTYPE node in an existing document?


> The DOM level 2 spec is quite clear that the DOCTYPE node is a
> readonly property of the Document, and that all the properties of a
> DocumentType object are readonly. Is it acceptable to add the ability
> to write readonly properties in a specific implementation according
> to either DOM or IDL? Might somebody be depending on the readonly
> nature of DocumentType?

Xalan DOM 2 DOM transformation takes an empty Document object, which means 
that DOCTYPE elements set in the stylesheet are ignored. I hope the latest 
release of Xalan uses DOM3 and doesn't have the same problem anymore.

Just in case if anybody has the same problem, here is a code example 
corrected based on Elena's comments (though the old code with the 
appendChild() worked exactly the same way - probably Xerces specific 
implementation which has a special handling for doctype type of node):


        // do DOM 2 DOM transformation. set doctype using xsl:output
        // workaround for the missing document type
        Properties prop = transformer.getOutputProperties();
        if ((prop.getProperty("doctype-system") != null
                || prop.getProperty("doctype-public") != null)
                && outDocument.getDocumentElement() != null) {
                DOMImplementation impl = 
docBuilder.getDOMImplementation();
                DocumentTypeImpl doctypeImpl =
                        new DocumentTypeImpl (
                                (CoreDocumentImpl) outDocument,
 outDocument.getDocumentElement().getNodeName(),
                                prop.getProperty("doctype-public"),
                                prop.getProperty("doctype-system"));
                if (doctypeImpl != null)
                        outDocument.insertBefore(doctypeImpl, 
outDocument.getDocumentElement());
        }