Having been writing code that operates on XML for a while, I have always wondered what is the reason for having both Nodes and Elements? (We know what the differences are). Both of them represent tags (more or less) and having different methods, just makes the code complicated.
Are there any special semantics or practical reasons, or is it just the fact that the DOM spec was committee generated?
Node is a base class of Element - pretty much everything in an Xml document is a Node, for example:
<!ENTITY...>
<xml a="myAttribute">
SomeText
<!-- A comment -->
</xml>
In the above example:
<!ENTITY...>
is an entity<xml ...
is an elementa="myAttribute"
is an attributeSomeText
is a text node <!-- A comment -->
is a commentAll of the above inherit from Node, in fact in the above example myAttribute
is also a text node.
Node is more generic than element. Check out this page for all the different 'things' a Node can stand for. An Element is just one of those possibilities, which corresponds to the tags. It is important to stress that nodes do not generally represent XML tags.
For example, <a>blah</a>
contains two nodes. The first is an 'element' representing the <a>
tag, the second is a text node containing "blah".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With