文章分类 Classification
JS获取XML内容!
稿件来源: 太阳光网页设计 撰稿作者: 太阳光 发表日期: 2008-10-19 14:45:36 阅读次数: 790 查看权限: 游客查看
JS获取XML内容的过程
XML
<?xml version="1.0" encoding="GB2312"?>
<myfile>
<title>tttt</title>
<author>ajie</author>
<email>ajie@aolhoo.com</email>
<date>20010115</date>
</myfile>
<myfile>
<title>tttt</title>
<author>ajie</author>
<email>ajie@aolhoo.com</email>
<date>20010115</date>
</myfile>
JS:
<html>
<head>
<script language="JavaScript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("myfile.xml");
root = xmlDoc.documentElement;
//nodes = xmlDoc.documentElement.childNodes;
document.all("title").innerText = root.childNodes.item(0).text;
document.all("author").innerText = root.childNodes.item(1).text;
document.all("email").innerText = root.childNodes.item(2).text;
document.all("date").innerText = root.childNodes.item(3).text;
</script>
<title>在HTML中调用XML数据</title>
</head>
<body bgcolor="#FFFFFF">
<b>标题: </b>
<span id="title"> </span><br>
<b>作者: </b>
<span id="author"></span><br>
<b>信箱: </b>
<span id="email"></span><br>
<b>日期:</b>
<span id="date"></span><br>
</body>
</html>
<head>
<script language="JavaScript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("myfile.xml");
root = xmlDoc.documentElement;
//nodes = xmlDoc.documentElement.childNodes;
document.all("title").innerText = root.childNodes.item(0).text;
document.all("author").innerText = root.childNodes.item(1).text;
document.all("email").innerText = root.childNodes.item(2).text;
document.all("date").innerText = root.childNodes.item(3).text;
</script>
<title>在HTML中调用XML数据</title>
</head>
<body bgcolor="#FFFFFF">
<b>标题: </b>
<span id="title"> </span><br>
<b>作者: </b>
<span id="author"></span><br>
<b>信箱: </b>
<span id="email"></span><br>
<b>日期:</b>
<span id="date"></span><br>
</body>
</html>
关键词: js获取XML内容,javascript,xml 编辑时间: 2010-03-12 8:52:25
1
高兴0
支持0
搞笑0
不解0
谎言0
枪稿0
震惊0
无奈0
无聊0
反对0
愤怒
50%(1)
50%(1)
- 中搜索:JS获取XML内容!
- 中搜索:JS获取XML内容!
- 暂无评论
文章图片 article Pictrue
网友评论