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 3

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.

Extract Data Using an External XML File
To load an external XML file using XML-DSO, you have to explicitly include the object and use a small bit of JavaScript.

First create an XML-DSO object, with the ID myXML. Add the width and height attributes to the <OBJECT> tag and set their values to 0. This ensures that the XML-DSO object won't occupy any space in your Web page.

Next, create a table with datasrc as myXML—similar to Listing 2. The code extracts the data using <DIV> tags (within TD tags) using datafld as the message for the first column and the URL for the second column. The <SCRIPT> tag is added because here the external XML uses JavaScript to explicitly state the XML file you want to load.

Set the variable xmlDso to myXML.XMLDocument. myXML refers to the object you have created. Next, load example3.xml using the XML-DSO's load() method. The file example3.xml binds to the object, myXML.

<!-- example3.xml -->
<?xml version="1.0" ?>
		<message>JavaScript Ticker using XML DSO</message>
Now, consider the following HTML page:

<!-- example3.htm -->
<title>XML DSO-example3.htm</title>
<script language="JavaScript">
function load() {
	var xmlDso=myXML.XMLDocument;
<body bgcolor="#FFFFFF" onLoad="load()">

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

<table datasrc="#myXML" border="1">
		<td><div datafld="message"></div></td>
		<td><div datafld="URL"></div></td>

The output should be:



JavaScript Ticker using XML DSO


The above script is very specific. Here's a more generic script:

<script language="JavaScript">
var xmlDso;
function load(xmlFile, objName) {
Now, to load any XML file use: 

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