Dale Worley wrote:
On Mon, 2008-02-18 at 19:43 +0100, Adrian Schubert wrote:
There's something I don't understand about the DOM parsing. When I'm
traversing the DOM, looking for a particular node with a given name,
each time I have to filter out the nodes that are NOT elements, and NOT
null.
I know that you will see the attributes of the element as child nodes of
the element's node. This is a little odd, but IIRC it conforms to the
philosophy of XSLT, which is that attributes are children of the element
in very much the same way as text content and sub-elements.
This is not true. Attributes are not children in the DOM, and they are not
children in the XPath data model:
http://www.w3.org/TR/xpath#attribute-nodes
"Each element node has an associated set of attribute nodes; the element is
the parent of each of these attribute nodes; however, an attribute node is
not a child of its parent element.
NOTE: This is different from the DOM, which does not treat the element
bearing an attribute as the parent of the attribute (see [DOM])."
So, in the XPath data model, the element is the parent of its attributes,
but they are not its children. In the DOM, the element is not the parent
of its attributes, nor are they its children.
Dave