Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM – Nodes

XML DOM Nodes


In the DOM, every component in an XML document is a node.


DOM Nodes

According to the DOM, every component in an XML document is aNode.

The DOM specifies it like this:


DOM Examples

Look at the following XML file (books.xml):

books.xml file code:

<

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 . All other nodes in the document are contained in it.

Root Node There are four node.

first nodes, each with four nodes: , , and , each of which contains a text node: "Everyday Italian", "Giada De Laurentiis", "2005" and "30.00".


Text is Always Stored in Text Nodes

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

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

In this example:2005, the element node , has a text node with the value "2005".

"2005" Either element's value!