js 解析xml 文件
<HTML>
<HEAD>
<TITLE>在html中调用xml数据</TITLE>
<script language="javaScript" for="window" event="onload">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("article.xml");
nodes=xmlDoc.documentElement.childNodes;
title.innerText = nodes.item(0).text;
author.innerText = nodes.item(1).text;
email.innerText = nodes.item(2).text;
blogname.innerText = nodes.item(3).text;
url.innerText = nodes.item(4).text;
date.innerText = nodes.item(5).text;
</script>
</HEAD>
<BODY>
<b>标题:</b><span id="title"></span><br>
<b>作者:</b><span id="author"></span><br>
<b>信箱:</b><span id="email"></span><br>
<b>我的Blog名:</b><span id="blogname"></span><br>
<b>我的Blog地址:</b><span id="url"></span><br>
<b>日期:</b><span id="date"></span><br>
</BODY>
</HTML>
<HEAD>
<TITLE>在html中调用xml数据</TITLE>
<script language="javaScript">
var count = 0;
function getParseXml(){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("parseXML.xml");
nodes=xmlDoc.documentElement.childNodes;
var allItem="";
if(nodes!=null){
var str=document.all.inpuText.value;
//alert("str==="+str);
//alert("nodes.item(0).text==="+nodes.item(0).text);
for( var i=0;i < nodes.length;i++)
{
if(count==0)13821387323
{
if(str.indexOf(nodes.item(i).text))
allItem += nodes.item(i).text;
}
if(count>0)
{
if(str.indexOf(nodes.item(i).text)+1)
allItem += nodes.item(i).text;
}
}
}
document.all.inpuText.value=allItem;
count++;
}
function test(){
str="1122334455";
alert(str.indexOf(2));
if(str.indexOf(2))alert("ss") ;
}
</script>
</HEAD>
<BODY>
<form name ="form1" method="post">
<input type="text" value=""name="inpuText">
<input type="Button" value="button" name="buttonName" onclick="getParseXml();">
</form>
</BODY>