js读取xml文件
xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<main id="id1">
<n id="f1"><name>jifew1</name></n>
<n id="f2"><name id="idv">jifew2</name></n>
</main>
</root>
<root>
<main id="id1">
<n id="f1"><name>jifew1</name></n>
<n id="f2"><name id="idv">jifew2</name></n>
</main>
</root>
js:
window.onload=function(){
var xml=new ActiveXObject("MSXML2.DOMDocument.5.0"); //创建对象
xml.async=false; //同步
xml.load("x.xml"); //载入
alert(xml.documentElement.selectNodes("main/n/name")[1].tagName); //取标签名
alert(xml.documentElement.selectNodes("main/n/name")[1].text); //取值
alert(xml.documentElement.selectNodes("main/n/name")[1].getAttribute("id")); //取属性
}