我的分数不怎么多了
请大家见谅asp.net
用javascript 读取网站XML目录下的一个XML文件,aspx 页面中引用一个js文件,js文件主体内容如下:
      
  var xmlDoc=null;
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");     
        xmlDoc.async=false;
xmlDoc.resolveExternals   =   false;
var xmlFile = window.location.href ;
        xmlFile = xmlFile.substring(0,xmlFile.lastIndexOf("/")+1) + "XML/piclist.xml"; //获取xml文件路径 
        
        alert(xmlFile);//测试表明:能够获取到完整路径
       xmlDoc.load(xmlFile);       
        
        
       var node = xmlDoc.selectNodes("//pic_list/pic"); //两种取参数的方法都试过,均不行
       alert(node.length);//测试结果为:0
为什么取不到结果呢?
将相同的js代码在.htm文件中被引用,直接点击htm页面则可以看到结果

解决方案 »

  1.   

    XML 格式如下<?xml version="1.0" encoding="gb2312"?>
    <pic_list>
    <pic>
    <pic_path>http://avatar.profile.csdn.net/3/A/B/1_comsharp.jpg</pic_path>
    <pic_link>http://news.163.com</pic_link>
    <pic_text>图片</pic_text>
    </pic></pic_list>
      

  2.   

       <script type="text/javascript">
             function CreateXMLDOM()
             {
                //列出MSXML 所有版本
             var arrSignatures=["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
             //遍历每一个预定义的XML DOM
             for (var i=0; i <arrSignatures .length ; i ++)
             {
               try 
               {
                  var oXmlDom= new ActiveXObject (arrSignatures [i])
                  return oXmlDom; 
               } catch(oError){}
             }
             throw new Error ("MSXML not installed on your system.");
             }
          </script>
      

  3.   

    谢谢jasondct
    老兄问题已解决