当前位置:主页>xml>文章内容
XML在Web中的简单应用
来源: 作者: 发布时间:2007-04-04  

首先建立一个Area.html,很简单包含一个省份的select元素和一个城市的界面元素:

<html>
<head>
<title>Area Demo</title>
</head>
<body>
<select id="province" size=1 onchange="loadCity()">
<option value="city01.xml">  江苏  </option>
<option value="city02.xml">  º湖南 </option>
<option value="city03.xml">  湖北  </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();
/**
 * 装载城市数据
 */
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>
</html>

然后建立三个省份的城市数据文件,分别命名为city01.xml,city02.xml,city03.xml

<?xml version="1.0" encoding="GB2312"?>
<Cities Province="江苏">
 <City name="南京"/>
</Cities>

<?xml version="1.0" encoding="GB2312"?>
<Cities Province="湖南">
 <City name="长沙"/>
</Cities>

<?xml version="1.0" encoding="GB2312"?>
<Cities Province="湖北">
 <City name="武汉"/>
</Cities>

保存,在ie6浏览通过,理论上可以在ie5一上浏览器跑。


 
上一篇:XML串行化数据基础   下一篇:将HTML表单数据存储为XML格式
 
  相关文章
·XML串行化数据基础
·将HTML表单数据存储为XML格式
·XML将走向何方
·XSL学习心得 - 调用属性值
·概述IE和SQL2k开发一个XML聊天程序
·XSL学习心得 - 制作图像超链接
·XML CDATA的作用
·在Eclipse中利用XMLBuddy开发XML
·如何在HTML中引用XML数据
·读写xml文件的2个小函数
·W3C有意推广XML新标准 为兼容性吵翻了
·使用XSL将XML文档中的CDATA注释输出为H
 
【关闭窗口】
推荐本站资源
最新文章