Using the XML Data Source Object

The XML Data Source Object (DSO) is a Microsoft ActiveX control built into Microsoft Internet Explorer 4+. Using this object, it is possible to extract content from an external XML file or XML data embedded in the HTML file into a HTML page. In this article, I'll explain how to include the XML DSO, extract content from an external XML file, extract XML data from XML data embedded in the webpage and manipulation using JavaScript

Using the XML Data Source Object

Introduction:

The XML Data Source Object (DSO) is a Microsoft ActiveX control built into Microsoft Internet Explorer 4+. Using this object, it is possible to extract content from an external XML file or XML data embedded in the HTML file into a HTML page. In this article, I'll explain how to include the XML DSO, extract content from an external XML file, extract XML data from XML data embedded in the webpage and manipulation using JavaScript.

Implementation:

Initializing an XML-DSO object is done using the <OBJECT> tag. The CLASSID for the XML-DSO is:

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

The above ID uniquely identifies the XML-DSO. Thus we initialize this control in a webpage as follows:

Note that, in the code for example1.htm, we have not initialised any XML-DSO object. Thus, when you use a XML data island, the object is implicitly created.

In the above code, we have included a XML data island using the <XML> tag. We have assigned it an ID, xmldb for use later. Now, we can extract data from the XML data island using the HTML tags like <A>, <SPAN>, <DIV> etc. As you can see, we have extracted data using the <SPAN> tag. Note the attributes, datasrc and datafld in the <SPAN> tag. datasrc is used to specify the ID of the data island you want to extract data from. datafld is used to specify the XML tag you want the data from (here, name in first <SPAN> and sex in second <SPAN>).

Note that we have two <name> and <sex> tags in our XML data island, but using the above method we can extract only the first instances of these tags. To extract all instances, this can be done using the <TABLE> tag. Take a look at the following example:

Here, we have used the <TABLE> tag and extract the contents using the HTML tag, <DIV>, within the HTML column tag, <TD>. The table will automatically iterate through each instance of <member> (the parent of <name> and <sex>). Thus we can dispaly all the names and ages in a formatted way.

Now, we'll take a look at how to extract contents from an external XML file using XML-DSO. Consider the following XML file:

Observe the code of example3.htm. First we have created a XML-DSO object with id as myXML. Note that we have added the width and height attributes to the <OBJECT> tag and set their values to 0. This is because we just want to create a XML-DSO object but do not want it to occupy any space in the webpage. Next, we have created a table with datasrc as myXML, similar to example2. We have extracted the content using <DIV> tags (within TD tags) with datafld as message for first column and URL for second column. The additional code here is the <SCRIPT> we have added. As you can see in the script, we have set the variable xmlDso to myXML.XMLDocument which refers to the object we have created. Next, we load example3.xml using the XML-DSO's load() method. Thus, now the file example3.xml is bound to the object, myXML. Everything else is similar to the previous examples.

Thus, when we want to load an external XML file using XML-DSO, we have to explicitly include the object and also use a small bit of JavaScript to load the external XML file. The above script is very specific and cannot be used to load just any XML file. A more generic script is as follows:

The above script is self explanatory: Initially we store the entire data of the data file into a variable memberSet using the recordset method. The moveNext() method points to the next data item (next row). Some of other methods that can be used are :

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.

Note that, in the above methods, the data is pointed relative to parent of the nodes being displayed.

XML Ticker using XML DSO:

So far we have considered simple examples. Now, we will consider a more dynamic example, "XML Ticker using XML DSO". In this example, the ticker reads it's messages and URLs from an external example file and ticks the messages with the specified delay.

XML and JavaScript Tutorialby Premshree Pillai
This tutorial shows how we can use XML and client side JavaScript. We will see how we can display the contents of a XML file using JavaScript, accessing child elements, manipulating elements etc.

Display XML in tree format using Javascriptby Premshree Pillai
In this article, I present a XML based client-side JavaScript that reads data from an external XML file, traverses the XML data and displays the same in a tree format. I'll use the XMLDOM ActiveX object built into Microsoft Internet Explorer for the same.

Using the XML Data Source Objectby Premshree Pillai
The XML Data Source Object (DSO) is a Microsoft ActiveX control built into Microsoft Internet Explorer 4+. Using this object, it is possible to extract content from an external XML file or XML data embedded in the HTML file into a HTML page. In this article, I'll explain how to include the XML DSO, extract content from an external XML file, extract XML data from XML data embedded in the webpage and manipulation using JavaScript

XML Converter for MySQL databaseby Rustem
MySQL has no native facilities for dealing with XML. This does not mean we are left out of the XML evolution. RustemSoft XML Converter has ‘MySQL to XML’ support.

Creating An XML Newsfeedby Jeff Anderson
A full explanation of how to take an XML newsfeed from moreover, amazon affiliates, google or any of the other current feed providers, and turn it into a display page using a little ASP.

XML Tickerby Premshree Pillai
This is an XML based JavaScript Ticker that can tick any number of messages. The ticker works with IE only. The ticker reads it's contents, i.e the ticker style, text to be displayed, the link for that particular message from a XML file.

Batch processing XML with XSLT 2.0by Krunal Patel
What you need is an XML version of the directory listing. Then, you could use that XML file as the single input file to XSLT and process each file using XSLT. It would be wonderful if you could do the directory processing in XSLT directly. Unfortunately, with all the power of XSLT -- and particularly XSLT 2.0 -- the language still doesn't have directory operations.