Home arrow XML arrow Page 2 - Roaming through XMLDOM: An AJAX Prerequisite

Roaming through XMLDOM: An AJAX Prerequisite

The twin tasks of the XMLHttp are handling the HTTP request, and then processing the XML response. The first one is easily done by writing the appropriate syntax for creating this object. This is what is accomplished in AJAX by invoking the new constructor for XMLHTTP object. This is but one of the objects of the XMLDOM -XML Document Object Model. In this article, we look at XMLDOM in some detail before calling the XML document in an AJAX rendition in a future article.

Author Info:
By: Jayaram Krishnaswamy
Rating: 5 stars5 stars5 stars5 stars5 stars / 19
February 20, 2006
  1. · Roaming through XMLDOM: An AJAX Prerequisite
  2. · Getting at the Innards of an XML Document
  3. · Continuing the Dissection
  4. · Manipulating the XML Document

print this article

Roaming through XMLDOM: An AJAX Prerequisite - Getting at the Innards of an XML Document
(Page 2 of 4 )

We will briefly look at some of the XML Dom objects. In order to show how the code accesses the various parts of a document, consider the following well formed XML document WebClass.xml which is located on my hard drive at:

C:/Documents and settings/computer user/Desktop/todo/Ajax/WebClass.xml.

XML document probed

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!-- My students who attended my web programming class -->
<student id="1">
<name>Linda Jones</name> 
<legacySkill>Access, VB5.0</legacySkill>
<student id="2">
<name>Adam Davidson</name> 
<legacySkill>Cobol, MainFrame</legacySkill>
<student id="3">
<name>Charles Boyer</name> 
<legacySkill>HTML, Photoshop</legacySkill>
<student id="4">
<name>Charles Mann</name> 
<legacySkill>Cobol, MainFrame</legacySkill>

Slicing the XML document

First things first: we need to instantiate an XMLDocument object. This is done easily by running the following code as shown:

var xml_doc = new ActiveXObject("Microsoft.XMLDOM"); 
xml_doc.async = false; 
xml_doc.load ("C:/Documents and settings/computer user/Desktop/
todo/Ajax/WebClass.xml"); </SCRIPT>

After this step we will look at a number of properities that can be accessed using code.

First Child and Last Child Properties

These properties can be accessed if you insert the following lines after loading the document as shown above but before </Script>,

document.write ("This documents first child is a " + 
document.write ("This document's  last child= " + 

and if you display it in a browser you would see the following:

This documents first child is a #comment
This document's last child= student

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials