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

XML DOM - Node Tree


May 27, 2021 XML DOM


Table of contents


XML DOM node tree

In XML DOM, you can think of an XML document as a tree structure, that is, a node tree.

XML DOM treats XML documents as a node tree.

All nodes in the tree have relationships with each other.


XML DOM node tree

XML DOM treats XML documents as a tree structure. This tree structure is called the node tree.

All nodes can be accessed through this tree. They can be modified or deleted, or new elements can be created.

This node tree shows the collection of nodes and their connections. The tree starts at the root node and then grows branches to the text node at the lowest level of the tree:

XML DOM - Node Tree

The picture above shows the XML file .xml.


Parent, child, and peer nodes

Nodes in the node tree have hierarchical relationships with each other.

Parent, child, and peer nodes are used to describe this relationship. T he parent node has child nodes, which are at the same level and are called peer nodes (brothers or sisters).

  • In a node tree, the node at the top is called the root node
  • Each node outside the root node has a parent node
  • A node can have any number of child nodes
  • A leaf is a node that has no child nodes
  • A peer node is a node that has the same parent node

The following image shows a part of the node tree and the relationship between nodes:

XML DOM - Node Tree

Because XML data is constructed as a tree, it can be traversed without knowing the exact structure of the tree and the type of data it contains.

You'll learn more about traversing the node tree later in this tutorial.


The first child node - the last child node

Take a look at the following XML clip:

<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>

In the XML above, the element is the first child node of the element, while the element is the last child node of the element.

In addition, the element is the parent node of the element.

Tip: There are 12 node types in XML, of which 5 are the most common basic node types, as follows:

  • Elements: Elements are the basic components of XML. , which describes the basic information of XML.
  • Property: A property node contains information about an element node, usually contained within an element, that describes the properties of an element.
  • Text: Contains a lot of text information or is just blank.
  • Document: A document node is the parent of all other nodes in the entire document.
  • Note: Comments are descriptions and comments about relevant information.