XML DOM - node
In the DOM, XML document is a node for each component.
DOM node
According DOM, XML document is anode for each component.
DOM is such a requirement:
- The entire document is a document node
- Each element is an XML element node
- Text contained in the XML element is a text node
- Each XML attribute is an attribute node
- Comments are comment nodes
DOM Examples
Look at the following XML document ( the Books.xml ):
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In the above XML, the root node is <bookstore>. All other nodes in the document are included in <bookstore> in.
The root <bookstore> four <book> node.
The first <book> node has four nodes: <title>, <author>, <year> and <price>, where each node contains a text node, "Everyday Italian", "Giada De Laurentiis", " 2005 "and" 30.00. "
Text is always stored in a text node
In the DOM processing a common mistake is to think that the element nodes that contain text.
However, the text of an element node is stored in a text node.
In thisexample: <year> 2005 </ year >, the element node <year>, have a value of "2005" in the text node.
"2005" isnot <year> element's value!