0

团队,

我在 chrome 中收到“未捕获的错误:NamespaceError:DOM Exception 14”。我已经尝试了很多。路径适用于“ 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>
4

0 回答 0