0

So there is this piece of code that is causing me problems in IE 11 and chrome too. I am not sure what is happening since it should be working, this is old code I am helping fix, but it looks good to me. I am creating an xml document object and calling the setproperty method, but it is saying that the function is undefined. This is what my code looks like

if (window.DOMParser) {
        var parser = new DOMParser();
        xmlDoc = parser.parseFromString(xml, "text/xml");
    } else {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(xml);
    }        
    console.log(xmlDoc);
    console.log(typeof xmlDoc.setProperty);

and the result of the console.log

enter image description here

Anybody knows what is happening?

Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • What makes you think you can call `setProperty` on an XML document? None of IE11, Firefox and Chrome appears to support this method. What is the code that calls `setProperty` trying to achieve? – Luke Woodward Jul 01 '14 at 20:27
  • @LukeWoodward not really sure either, something about setting the language for xpath `xmlDoc.setProperty("SelectionLanguage", "XPath");` – Jack Thor Jul 01 '14 at 20:35

1 Answers1

0

The setProperty method you mention belongs to an ActiveXObject used to parse XML. There is no such method on the XML document returned by the DOMParser, and this is why you are getting the error in browsers that support DOMParser.

If you want to use XPath to query XML in JavaScript, I would recommend using document.evaluate instead. See also this question.

Community
  • 1
  • 1
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104