W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2001

Re: HRE when adding to Doc created with DTD

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Wed, 4 Apr 2001 09:23:55 -0400
To: James <jhughes@kos.net>
Cc: www-dom@w3.org
Message-ID: <OF7C5A94D5.0FD551F3-ON85256A24.0048E422@pok.ibm.com>

>I create my Document object like this:
>    ruledoc = new DocumentImpl();

You're probably aware of this, but that constructor is not portable --
you're explicitly accessing a specific implementation of the DOM, and you
then have to add the root element which is a slight violation of the DOM
architecture. It's better to use the DOMImplementation.createDocument()
call, which is portable and creates the Document and the root element
simultaneously. (Obtaining the DOMImplementation itself is still a
nonportable step, but that's a one-time operation.)

>rule.getOwnerDocument().getFirstChild().appendChild(rule);

The first child of the Document is _NOT_ necessarily the root element.
If you're inadvertently trying to append rule to a comment, or to the
DocumentType node, the DOM will quite correctly tell you that this is not
acceptable. The fact that validation affects this suggests that it is the
DocumentType that's surprising you.

If you really want to do so, you can check this by printing out
     rule.getOwnerDocument().getFirstChild().getNodeType()
but simply switching to
     rule.getOwnerDocument().getDocumentElement().appendChild(rule);
should fix the problem.


______________________________________
Joe Kesselman  / IBM Research
Received on Wednesday, 4 April 2001 09:24:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT