5.3 Attribute Nodes
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).
Elements never share attribute nodes: if one element node is not
the same node as another element node, then none of the attribute
nodes of the one element node will be the same node as the attribute
nodes of another element node.
NOTE:
The = operator tests whether two nodes have the
same value, not whether they are the same node. Thus
attributes of two different elements may compare as equal using
=, even though they are not the same node.
A defaulted attribute is treated the same as a specified attribute.
If an attribute was declared for the element type in the DTD, but the
default was declared as #IMPLIED, and the attribute was
not specified on the element, then the element's attribute set does
not contain a node for the attribute.
Some attributes, such as xml:lang and
xml:space, have the semantics that they apply to all
elements that are descendants of the element bearing the attribute,
unless overridden with an instance of the same attribute on another
descendant element. However, this does not affect where attribute
nodes appear in the tree: an element has attribute nodes only for
attributes that were explicitly specified in the start-tag or
empty-element tag of that element or that were explicitly declared in
the DTD with a default value.
An attribute node has an
[expanded-name]
and a
[string-value]
. The
[expanded-name]
is computed by
expanding the QName specified in
the tag in the XML document in accordance with the XML Namespaces
Recommendation XMLNAMES. The namespace URI of the
attribute's name will be null if the QName of the attribute does not have
a prefix.
NOTE:
In the notation of Appendix A.3 of XMLNAMES,
the local part of the expanded-name corresponds to the
name attribute of the ExpAName element; the
namespace URI of the expanded-name corresponds to the ns
attribute of the ExpAName element, and is null if the
ns attribute of the ExpAName element is
omitted.
An attribute node has a
[string-value]
. The
[string-value]
is the normalized value
as specified by the XML Recommendation XML. An
attribute whose normalized value is a zero-length string is not
treated specially: it results in an attribute node whose
[string-value]
is a zero-length
string.
NOTE:
It is possible for default attributes to be declared in an
external DTD or an external parameter entity. The XML Recommendation
does not require an XML processor to read an external DTD or an
external parameter unless it is validating. A stylesheet or other facility that assumes
that the XPath tree contains default attribute values declared in an
external DTD or parameter entity may not work with some non-validating
XML processors.
There are no attribute nodes corresponding to attributes that
declare namespaces (see XMLNAMES).
|