Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML DOM - Node


May 27, 2021 XML DOM


Table of contents


XML DOM node


In DOM, each component of the XML document is a node.

The entire document is a document node, and each XML tag is an element node.


The DOM node

According to the DOM, each component of the XML document is a node.

The DOM states as this:

  • The entire document is a document node
  • Each XML element is an element node
  • The text contained in the XML element is a text node
  • Each XML property is a property node
  • A comment is a comment node

The DOM instance

Take a look at the XML file below (.xml):

<?xml version="1.0" encoding="ISO-8859-1"?>
<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 XML above, the root node is the .lt;bookstore. All other nodes in the document are included in the .

The root node, the bookstore, has four nodes, the lt;book, and the node.

The first node has four nodes: "Italian Everyday," "Giada De Laurentiis," "2005," and "30.00."


Text is always stored in a text node

A common mistake in DOM processing is to think that element nodes contain text.

However, the text of the element node is stored in the text node.

In this example: .lt;year.gt;2005</year>, element node slt;year>, has a text node with a value of "2005".

"2005" is not the value of the element!

This section describes the knowledge of XML DOM nodes, and in the next section you will learn about the XML DOM node tree.