devxlogo

Making Use of the XML Data Source Object

Making Use of the XML Data Source Object

he XML Data Source Object (DSO) is a Microsoft ActiveX control that’s been built into Microsoft Internet Explorer since version 4. This object allows you to extract content from an external XML file or XML data embedded in the HTML file into a HTML page.

You can use the XML-DSO in a Web page to extract content from an external XML file, extract XML data from XML data embedded in the Web page, and manipulate that data using JavaScript. However, it is not advisable to use this object for the Internet since XML-DSO only works on MSIE 4+ browsers, which can raise compatibility issues. It is much more advisable to use XML-DSO for intranets.

Getting Started
To initialize the XML-DSO object, use the tag. The CLASSID for the XML-DSO is:

CLSID:550dda30-0541-11d2-9ca9-0060b0ec3d39

This ID uniquely identifies the XML-DSO. Initialize this control in a Web page using this code:

Though most OBJECTs have a number of parameters associated with them, the XML-DSO does not require any.

Extract Data Using an XML Data Island
First, include an XML data island by using the tag. Next, assign it an ID, xmldb?for use later. Data is actually extracted using HTML tags: , ,

, etc. The code in Listing 1 uses the tag. The datasrc attribute specifies the ID of the data island from which you want to extract data. The datafld attribute specifies the XML tag from which you want the data. So, the first extracts the name, and the second extracts the gender.

Note that the code does not initialize an XML-DSO object. This is because the use of an XML data island implicitly creates one.

The output should be:

Premshree Pillaimale

Note that there are two and tags in the XML data island. Using this method, you can only extract the first instances of these tags. The code in Listing 2 extracts all instances using the

tag:

The output should be:

Name

Sex

Premshree Pillai

male

Vinod

male

In Listing 2, the

tag extracts data using
tag within the
tag. The table will automatically iterate through each instance of (the parent of and ).

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 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

tags (within TD tags) using datafld as the message for the first column and the URL for the second column. The
Message URL

devx-admin

Share the Post: