RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Making Use of the XML Data Source Object  : Page 4

The XML Data Source Object is an ActiveX control that allows you to manipulate data between XML files and HTML pages. This article will show you the basics of how to extract content from various XML data sources and how to present that data using a little JavaScript.

Use XML-DSO and JavaScript Together
Suppose you have an XML file that contains names, email addresses, and phone numbers. You want to use it to build an app that displays the records of each person—one at a time. Users would browse each person's data using a "Next" and a "Previous" button. Javascript can help you do this.

The following code stores all the data in the file into a variable memberSet using the recordset method. The moveNext() method points to the next data item (next row). The script then loads the XML file example4.xml and stores the records in the variable memberSet. The first record will be displayed, but memberSet.moveNext() points to the next record in the file relative to the previously pointed data.

<!-- example4.xml -->
<?xml version="1.0" ?>
		<name>Premshree Pillai</name>
Here's the corresponding HTML file:

<!-- example4.htm -->
<title>XML DSO-example4.htm</title>
<script language="JavaScript">
function load() {
	var xmlDso=myDB.XMLDocument;

	/* Get the complete record set */
	var memberSet=myDB.recordset;

	/* Go to next data */
<body bgcolor="#FFFFFF" onLoad="load()">

<object id="myDB" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" 
width="0" height="0"></object>

<span datasrc="#myDB" datafld="name"></span>

The output should be:


Here are more ways to manipulate the XML-DSO using JavaScript:

  • movePrevious(): Point to previous data item.
  • moveFirst(): Point to first data item.
  • moveLast(): Point to last data item.
  • EOF: This property is used to check if we have reached the end of the data.

In the above methods, the data is pointed relative to the parent of the nodes being displayed.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date