Reputation: 1141
I'd like to know why the "DOMNode" class exists at all. It seems sensible only for the DOMElement to extend it. Therefor what's the purpose of it?
For example, why is the DOMAttr class ( http://php.net/manual/en/class.domattr.php ) based on DOMNode class? What is the relationship here? DOMAttr cannot have "childNodes" or... anything DOMNode provides.
It's just a key => value, isn't it?
To be precise, they do "share" something, when with new DOMAttr ('key','val') we get a DOMNode with nodeName == 'key' and nodeValue == 'val'; but... so what? Key/val pair still is not a DOM tree node, am I right?
Upvotes: 0
Views: 132
Reputation: 40681
Short answer, this question is not really a PHP question because PHP is just implementing the W3C specification of the DOM document.
In the spec, a Node is any part of the tree, including attributes, elements and text. It's not a matter of why have the DOMNode
because all these parts of the tree do share a lot of common properties which justifies them inheriting from a common parent.
Therefore it's fully justifiable why Element and Attribute would share a common ancestor in the interface design. I think the real question is why it was named a node
when node is usually a vertex of a tree/graph.
Upvotes: 1