Friday, July 6, 2012

Nodes aren't just elements...

Caught myself thinking that. So to set my mind right:


According to the DOM, everything in an XML document is a node.
The DOM says:
  • The entire document is a document node
  • Every XML element is an element node
  • The text in the XML elements are text nodes
  • Every attribute is an attribute node
  • Comments are comment nodes

Text is Always Stored in Text Nodes

A common error in DOM processing is to expect an element node to contain text.
However, the text of an element node is stored in a text node.
In this example: <year>2005</year>, the element node <year>, holds a text node with the value "2005".
"2005" is not the value of the <year> element!

This is exacerbated by JavaScript referring to nodeValue ....


No comments: