XML DOM Example


XML DOM Parsing

The following example uses an XML file books.xml。

Load an XML file
Load an XML string

Instance Explanation


XML DOM Properties and Methods

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.
FunctionloadXMLString()In external JavaScript, used to load XML strings.

Loading and Parsing XML Files - External Parsing Script
Load and parse an XML string - external parsing script

Instance Explanation


XML DOM Accessing Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Access a node using the index number in the node list
Use the length property to loop through nodes
View the element's node type
Loop through element nodes
Use node relationships to loop through element nodes

Instance Explanation


XML DOM Node Information

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Get the node name of an element node
Get text from a text node
Change the text of a text node
Get the node name and type of an element node

Instance Explanation


XML DOM Node Lists and Attribute Lists

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Get text from the first <title> element
Use the length property to loop through nodes
Get the element's attributes

Instance Explanation


XML DOM Node Tree Traversal

The following example uses an XML file books.xml。
FunctionloadXMLString()In external JavaScript, used to load XML strings.

Traverse node tree

Instance Explanation


XML DOM Browser Differences

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Display the length of the node list - Different results in IE and other browsers
Ignore Empty Text Between Nodes

Instance Explanation


XML DOM Navigating Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Get the node's parent node
Get the first child element of a node
Get the last child element of a node
Get the next sibling element of a node
Get the previous sibling element of a node

Instance Explanation


XML DOM Get Node Value

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Get the element's text value
Get the attribute's text value

Instance Explanation


XML DOM Change Node Value

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Change the element's text node
Using setAttribute to Change Attribute Values
Use nodeValue to change attribute values

Instance Explanation


XML DOM Removing Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Remove Element Node
Delete the current element node
Remove Text Node
Clear the text of a text node
Remove attribute by name
Remove attribute by object

Instance Explanation


XML DOM Replacing Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Replace Element Node
Replace Data in a Text Node

Instance Explanation


XML DOM Creating Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Create Element Node
Use createAttribute to Create Attribute Nodes
Using setAttribute to create an attribute node
Create Text Node
Create CDATA Section Node
Create Comment Node

Instance Explanation


XML DOM Adding Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Add a node after the last child node
Add a Node Before the Specified Child Node
Add a new attribute
Add data to a text node

Instance Explanation


XML DOM Cloning Nodes

The following example uses an XML file books.xml。
FunctionloadXMLDoc(), in external JavaScript, used to load XML files.

Copy a node and append it to an existing node

Instance Explanation


XML DOM XMLHttpRequest Object

A simple XMLHttpRequest example
Create a simple XMLHttpRequest and retrieve data from a TXT file.

Retrieve header information via getAllResponseHeaders()
Retrieve the header information of the resource (file).

Retrieve specified header information via getResponseHeader()
Retrieve the specified header information of a resource (file).

Retrieve ASP file contents
When a user types characters in an input field, how does the web page communicate with the web server?

Retrieve content from the database
How does a web page extract information from a database through the XMLHttpRequest object?

Retrieve XML file contents
Create an XMLHttpRequest to retrieve data from an XML file and display the data in an HTML table.

Instance Explanation


other extensions