0

Team,

I am getting "Uncaught Error: NamespaceError: DOM Exception 14" in chrome. I have tried lot. Path is working for the same xml in 'http://www.xpathtester.com/test'. But when i write code it is not working. Please help.

NOTE:
I have tried this http://www.w3schools.com/xpath/tryit.asp?filename=try_xpath_select_cdnodes example.


If possible; kindly explain the function xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null) and its arguments.

<!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>

And My xml is

<?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>
Kanagavelu Sugumar
  • 18,766
  • 20
  • 94
  • 101
  • Found a duplicate with an answer: http://stackoverflow.com/a/7257331/1352471 and a kb article http://support.microsoft.com/kb/294797/en-us The part you need is `xml.setProperty('SelectionNamespaces', 'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"');` and please never use w3schools, read why on http://w3fools.com – metadings Jul 16 '13 at 04:13
  • @metadings I got "Uncaught TypeError: Object # has no method 'setProperty' " – Kanagavelu Sugumar Jul 16 '13 at 04:29
  • i see, the setProperty method is IE only, but the linked answer solves the way of using namespaces in other browsers too. see also https://developer.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript#Implementing_a_User_Defined_Namespace_Resolver – metadings Jul 16 '13 at 04:51
  • seems really quite tricky in firefox, some code snippets: https://developer.mozilla.org/en-US/docs/Code_snippets/XPath – metadings Jul 16 '13 at 04:56
  • some more links: http://stackoverflow.com/questions/15113416/read-xml-with-namespace-in-ie-ff-and-chrome http://stackoverflow.com/questions/12769262/how-to-parse-namespace-xml-in-chrome-24-and-jquery-1-8-2 http://stackoverflow.com/questions/10181087/xml-findsomeelement-pulling-values-with-jquery-from-xml-with-namespace http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces – metadings Jul 16 '13 at 05:01
  • @metadings Thank you! I will go through all those links and let you know. – Kanagavelu Sugumar Jul 16 '13 at 05:29

0 Answers0