The simple application of XML in Web

Source: Internet
Author: User
Tags version
Web|xml

First set up a area.html, very simple contains the Select element of a province and the interface elements of a city:

<title>area demo</title>
<body>
<select id= "province" Size=1 >
<option value= "City01.xml" > Jiangsu </option>
<option value= "City02.xml" >º Hunan </option>
<option value= "City03.xml" > Hubei </option>
</select>
<select id= "City" size=1>
</select>
<xml id= "Xmlobj" ></xml>
<script language= "javascript" type= "Text/javascript" >
var provobj = document.all ("province");
var cityobj = document.all ("city");
var xmlhttp = document.all ("Xmlobj");
Loadcity ();
/**
* Load City Data
*/
function loadcity () {
cityobj.options.length = 0;
var file = Provobj.options[provobj.selectedindex].value;
Xmlhttp.async = false;
Xmlhttp.load (file);
var cities = xmlhttp.selectnodes ("cities/city");
var idx,name;

for (idx = 0; idx < cities.length; idx + +) {
Name = Cities[idx].getattribute ("name");
cityobj.options.length++;
Cityobj.options[cityobj.options.length-1].value = name;
Cityobj.options[cityobj.options.length-1].text = name;
}
}
</script>
</body>

Then the city data files of three provinces were established, named City01.xml,city02.xml,city03.xml

<?xml version= "1.0" encoding= "GB2312"?>
<cities province= "Jiangsu" >
<city name= "Nanjing"/>
</Cities>

<?xml version= "1.0" encoding= "GB2312"?>
<cities province= "Hunan" >
<city name= "Changsha"/>
</Cities>

<?xml version= "1.0" encoding= "GB2312"?>
<cities province= "Hubei" >
<city name= "Wuhan"/>
</Cities>

Save, browse through in IE6, theoretically can run in IE5 browser.



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.