XML DOM Traverse Node Tree

Traversing means looping through or traveling across the node tree.

Traversing the Node Tree

Often you want to loop an XML document, for example: when you want to extract the value of each element.

This is called “Traversing the node tree”

The example below loops through all child nodes of <book>, and displays their names and values: Continue reading XML DOM Traverse Node Tree

XML DOM Node List

A list of nodes is returned by the getElementsByTagName() method and the childNodes property.


DOM Node List

When using properties or methods like childNodes or getElementsByTagName(), a node list object is returned.

A node list object represents a list of nodes, in the same order as in the XML.

Nodes in the node list are accessed with index numbers starting from 0. Continue reading XML DOM Node List

XML DOM Node Information

The nodeName, nodeValue, and nodeType properties contain information about nodes.


Node Properties

In the XML DOM, each node is an object.

Objects have methods and properties, that can be accessed and manipulated by JavaScript.

Three important node properties are:

  • nodeName
  • nodeValue
  • nodeType

Continue reading XML DOM Node Information

XML DOM – Accessing Nodes

With the DOM, you can access every node in an XML document.


Accessing Nodes

You can access a node in three ways:

  1. By using the getElementsByTagName() method
  2. By looping through (traversing) the nodes tree
  3. By navigating the node tree, using the node relationships

Continue reading XML DOM – Accessing Nodes

XML DOM Nodes

According to the XML DOM, everything in an XML document is a node:

  • The entire document is a document node
  • Every XML element is an element node
  • The text in the XML elements are text nodes
  • Every attribute is an attribute node
  • Comments are comment nodes

Continue reading XML DOM Nodes

XML DOM Tutorial

What is the DOM?

The DOM defines a standard for accessing and manipulating documents:

“The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”

The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure.

The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure.

Understanding the DOM is a must for anyone working with HTML or XML.


Continue reading XML DOM Tutorial

XML on the Server

XML files are plain text files just like HTML files.

XML can easily be stored and generated by a standard web server.


Storing XML Files on the Server

XML files can be stored on an Internet server exactly the same way as HTML files.

Start Windows Notepad and write the following lines:

<?xml version="1.0" encoding="UTF-8"?>
<note>
  <from>Jani</from>
  <to>Tove</to>
  <message>Remember me this weekend</message>
</note>

Save the file on your web server with a proper name like “note.xml”.


Continue reading XML on the Server

XML Schema

An XML Schema describes the structure of an XML document, just like a DTD.

An XML document with correct syntax is called “Well Formed”.

An XML document validated against an XML Schema is both “Well Formed” and “Valid”.


Continue reading XML Schema

XML DTD

An XML document with correct syntax is called “Well Formed”.

An XML document validated against a DTD is both “Well Formed” and “Valid”.


What is a DTD?

DTD stands for Document Type Definition.

A DTD defines the structure and the legal elements and attributes of an XML document.


Continue reading XML DTD

XML, XLink and XPointer

XLink is used to create hyperlinks in XML documents.


  • XLink is used to create hyperlinks within XML documents
  • Any element in an XML document can behave as a link
  • With XLink, the links can be defined outside the linked files
  • XLink is a W3C Recommendation

XLink Browser Support

There is no browser support for XLink in XML documents.

However, all major browsers support XLinks in SVG.


Continue reading XML, XLink and XPointer