未捕获错误:NamespaceError:DOM异常14

时间:2013-07-16 03:48:18

标签: javascript xpath xmlhttprequest

我在Chrome中遇到“未捕获的错误:NamespaceError:DOM异常14”。我试了很多。 Path正在“http://www.xpathtester.com/test”中使用相同的xml。但是,当我编写代码时,它无法正常工作。请帮忙。

注意:
我试过这个http://www.w3schools.com/xpath/tryit.asp?filename=try_xpath_select_cdnodes例子。


如果可能的话;请解释函数xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null)及其参数。

<!DOCTYPE html>
<html>
<head>
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
   <script type="text/javascript">
   function loadXMLDoc(dname)
   {
     if (window.XMLHttpRequest)
     {
        xhttp=new XMLHttpRequest();
     }
     else
     {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     xhttp.open("GET",dname,false);
     xhttp.send("");
     return xhttp.responseXML;
   }

   function Test(){
     xml=loadXMLDoc("config.xml");
     path="/SOAP-ENV:root/SOAP-ENV:Envelope/SOAP-ENV:Body/child::node()";

     // code for IE
     if (window.ActiveXObject) {
       var nodes=xml.selectNodes(path);
       for (i=0;i<nodes.length;i++) {
          document.write(nodes[i].childNodes[0].nodeValue);
          document.write("<br>");
       }
      }
      // code for Mozilla, Firefox, Opera, etc.
      else if (document.implementation && document.implementation.createDocument){
        var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null); //Exception
        var result=nodes.iterateNext();
        while (result) {
           document.write(result.childNodes[0].nodeValue);
           document.write("<br>");
           result=nodes.iterateNext();
        }
      }
}
</script>
</head>
<body>
<button type="button" onclick=Test()>Display Date</button>
</body>
</html>

我的xml是

<?xml version="1.0"?>
<SOAP-ENV:root xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:Activate xmlns:m="http://schemas.method.com"><resultCode>0</resultCode>
</m:Activate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

0 个答案:

没有答案
相关问题