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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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" ?> <myDB> <member> <name>Premshree Pillai</name> <sex>male</sex> </member> <member> <name>Vinod</name> <sex>male</sex> </member> <member> <name>Santhosh</name> <sex>male</sex> </member> </myDB>

Here's the corresponding HTML file:

<!-- example4.htm --> <html> <head> <title>XML DSO-example4.htm</title> <script language="JavaScript"> function load() { var xmlDso=myDB.XMLDocument; xmlDso.load("example4.xml"); /* Get the complete record set */ var memberSet=myDB.recordset; /* Go to next data */ memberSet.moveNext(); } </script> </head> <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> </body> </html>

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.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



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