Why is Attr a Node? Can it have children? Can it be a child?
Answer:
Attr is a Node because its value is actually carried by its children, which may be a mixture of Text and EntityReference nodes, and because making it a Nodeallows us to store it in a NamedNodeMap for easy retrieval.
The getAttribute method hides this detail by returning a string representing the concatenation of all these children, and similarly setAttribute replaces theAttr's contents with a single Text node holding the new string. To create or manipulate other children of an Attr, you have to access the Attrnode directly via thegetAttributeNode and setAttributeNode methods, or by retrieving it from the element's "attributes" NamedNodeMap.
Section 1.1.1 of the Level 1 DOM Recommendation gives a list of which nodes can be parents and children of which other nodes. Attr is not a legal child of any node, so attempts to insert it as one will throw a DOMException (HIERARCHY_REQUEST_ERR).
No comments:
Post a Comment