How to use XML data in web design

Source: Internet
Author: User
Tags add object html page html tags include require version
web|xml| Design | The data 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 how to extract data from a variety of XML data sources and how to display that data using JavaScript.

The XML data source object DSO is a Microsoft ActiveX control, built on a later version of Microsoft IE4. This object allows you to extract content from an external XML file or embedded HTML file into an HTML page.

You can use XML-DSO in a Web page to pick content from an external XML file, extract the XML data from the XML that is embedded in the Web page, and then manipulate the data using JavaScript. However, it is not recommended to use this object on the Internet because DSO can only work in browsers above MSIE 4, so this can lead to some compatibility issues. Therefore, it is appropriate to use XML-DSO in intranet.

Begin

To initialize the Xml-dso object, we use the tag. The ClassID for XML-DSO are:

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

This ID uniquely identifies the XML-DSO. Use the following code to initialize the control in a Web page:

Although most objects require many parameters to be associated with them, XML-DSO does not require any parameters.

Extract data using an XML data island

First, you include an XML data island by using the tag. Second, assign it a id,xmldb--for later use. The data is actually extracted using HTML tags: , ,

, and so on. The code in Code Listing 1 uses the tag. The Datasrc property specifies the data island from which you want to extract the data. The DATAFLD property specifies the XML tag of the data you want. So, the first extracts the name, and the second extracts the gender.

Code Listing 1:

!--example1.htm-->


XML dso-example1.htm




Premshree Pillai
male


Vinod
male






Note that this code does not initialize a Xml-dso object. This is because one has been implicitly created in the use of the XML data island. The output should be:
  
Premshree Pillai
Male

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

tag to extract all instances:

The output will be:
Name Sex
Premshree Pillai Male
Vinod Male

In code Listing 2, the

tag in the
tag extracts data using the
tag. The table automatically repeats each instance of the ( and parent tags).

Code Listing 2:

!--example2.htm-->


XML dso-example2.htm



Premshree Pillai
male


Vinod
male










Name Sex


Extracting data using an external XML file

To load an external XML file with XML-DSO, you must explicitly include the object and use some JavaScript.

First create a Xml-dso object, using the ID myxml. Add width and Height properties to the tag, and then set their value to 0. This ensures that the Xml-dso object does not occupy any space on your Web page.

Second, use DATASRC to create a table like myXML--similar to code Listing 2. The code extracts data using the

tag (in TD-marked), uses DATAFLD as the first column of information, and uses the URL as the second column. Add the

Set variable XMLDSO to myxml.xmldocument. myXML references the object you have created. Next, load the example3.xml using the XML-DSO load () method. The file Example3.xml is connected to the object myXML.

!--Example3.xml-->
>


JavaScript Ticker using XML DSO
http://someURL.com

Now, look at the following HTML page:

!--example3.htm-->


XML dso-example3.htm


Width= "0" height= "0" >









message URL


The output should be:

Message URL
JavaScript Ticker using XML DSO http://someURL.com

The script above is very specialized. A more general script is given below:


Now, to load any XML file with:
Load ("Somexmlfile.xml", "Anyxmldsoobject");(csdn)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.