var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    xmlDoc.async = false;
    xmlDoc.load("mm.xml");
    if(xmlDoc.parseError.errorCode != 0)
    {
       var myErr = xmlDoc.parseError;
       alert("You have error " + myErr.reason);
    }
    else
    {
       alert(xmlDoc.xml);
    }
    xmlDoc = null;

解决方案 »

  1.   

    *.htm
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>selectNodes</title>
    </head><body>
    <script> 
    var xmldom = new ActiveXObject("Microsoft.XMLDOM");
    xmldom.async = false;  
    var url="041101.xml"; 
    xmldom.load(url); 
    var str=""; 
    //获取所有相关的子节点
    var nodes=xmldom.documentElement.selectNodes("//a/b"); 
    for(j=0;j<nodes.length;j++) 
    {
    //.getAttribute 方法为获取节点的属性
         str += "<div>"+ nodes[j].getAttribute("text") +" - "+ nodes[j].getAttribute("Attribute1") +"</div>";
    }document.write(str); 
    //window.open("qh309.htm", "", "fullscreen");  
    </script>
    </body>
    </html>041101.xml
    <?xml version="1.0" encoding="GBK"?>
    <a>
       <!--定义循环项目,内写属性.-->
       <b Attribute1="hi" text="1"/>
       <b Attribute1="我是谁呀..." text="2"/>
    </a>