JavaScript中读取xml文件

mytest.htm

<html>
<head>
<script language="JavaScript" for="window" event="onload">

 var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async="false";
 xmlDoc.load("myfile.xml");
 nodes=xmlDoc.documentElement.childNodes;
 title.innerText=nodes.item(0).text;
 author.innerText=nodes.item(1).text;
 email.innerText=nodes.item(2).text;
 date.innerText=nodes.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>

myfile.xml

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

<myfile>

<title>XML轻松学习手册</title>

<author>ajie</author>

<email>[email protected]</email>

<date>20010115</date>

</myfile>

本文出自 “一生�颐� �B��りますよ” 博客,谢绝转载!

你可能感兴趣的:(JavaScript,职场,休闲)