Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


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

Vinod

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.

 

 

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