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 2

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
Extract Data Using an XML Data Island
First, include an XML data island by using the <XML> tag. Next, assign it an ID, xmldb—for use later. Data is actually extracted using HTML tags: <ALT>, <SPAN>, <DIV>, etc. The code in Listing 1 uses the <SPAN> 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 <SPAN> extracts the name, and the second <SPAN> 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 Pillai male

Note that there are two <name> and <sex> 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 <TABLE> tag:

The output should be:

Name

Sex

Premshree Pillai

male

Vinod

male

In Listing 2, the <TABLE> tag extracts data using <DIV> tag within the <TD> tag. The table will automatically iterate through each instance of <member> (the parent of <name> and <sex>).



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