Re: Attributes and ownerDocument

msabin@cromwellmedia.co.uk wrote:

> According to PR-DOM-Level-1-19980818,
>
>   DOM Attribute objects inherit the Node interface, but
>   since they are not actually child nodes of the element
>   they describe, the DOM does not consider them part of
>   the document tree.
>
> If it weren't for the fact that the immediately following sentence,
>
>   Thus, the Node attributes parentNode, previousSibling,
>   and nextSibling have a null value for Attribute objects.
>
> doesn't mention ownerDocument I would have assumed that not being 'part
> of the document tree' would imply that this attribute would be null too.
>
> Can anyone reassure me that a null value would be conforming?

As the spec says:  "In the DOM Level 1, objects implementing some interface
"X" are created by a "createX()" method on the Document interface; this is
because all DOM objects live in the context of a specific Document."

As it also says:  "Since elements, text nodes, comments, processing
instructions, etc. cannot exist outside the context of a Document, the
Document interface also contains the factory methods needed to create these
objects. The Node objects created have a ownerDocument attribute which
associates them with the Document within whose context they were created."

As it also says, "Provides access to the Document object associated with
this Node. This is also the Document object used to create new Nodes. When
the Node is a Document this is null."

I see no justification whatsoever for believing that ownerDocument would be
null in the case of attributes.  If a user of the API were to rely on
ownerDocument to create new nodes as children of an AttributeNode, it
certainly had better be non-null.

Ray Whitmer
ray@imall.com

Received on Monday, 7 September 1998 12:14:39 UTC