Easy Tutorial
❮ Dom Attribute Met Element Isequalnode ❯

XML DOM Node Information


The nodeName, nodeValue, and nodeType properties contain information about the node.


Try It Yourself - Examples

The following examples use the XML file books.xml. loadXMLDoc(), located in an external JavaScript, is used to load the XML file.

Get the node name of an element node

Get text from a text node

Change text in a text node

Get the node name and type of an element node


Node Properties

In the XML DOM, every node is an object.

Objects have methods and properties, which can be accessed and manipulated using JavaScript.

The three important node properties are:


nodeName Property

The nodeName property specifies the name of the node.

Try it yourself.


nodeValue Property

The nodeValue property specifies the value of the node.


Get the Value of an Element

The following code retrieves the value of the text node of the first <title> element:

Example

xmlDoc = loadXMLDoc("books.xml");

x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
txt = x.nodeValue;

Result: txt = "Everyday Italian"

Example explanation:


Change the Value of an Element

The following code changes the value of the text node of the first <title> element:

Example

xmlDoc = loadXMLDoc("books.xml");

x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.nodeValue = "Easy Cooking";

Example explanation:


nodeType Property

The nodeType property specifies the type of the node.

nodeType is read-only.

The most important node types are:

Node Type NodeType
Element 1
Attribute 2
Text 3
Comment 8
Document 9

Try it yourself.

❮ Dom Attribute Met Element Isequalnode ❯