您的位置:首页 > Web前端 > JavaScript

JS获取XML内容!

2008-02-01 23:51 399 查看
XML


<?xml version="1.0" encoding="GB2312"?>


<myfile>


<title>tttt</title>


<author>QinHao</author>


<email>leo-qh@163.com</email>


<date>20080201</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>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: