later2013
later2013

Reputation: 41

Uncaught TypeError: Object #<Object> has no method 'setProperty'

I am using the below code in the javascript

text = LxmlHttp.responseText;
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, "application/xml");
xmlDoc.setProperty('SelectionLanguage', 'XPath');

I am getting this error: Uncaught TypeError: Object #<Object> has no method 'setProperty'

Please help me solve the issue.

TIA..

Hi Felix, I have the below xml structure

<?xml version="1.0"?>
<response status="200">
  <ns3:op xmlns="http://xxx.com/details/" 
              xmlns:ns2="http://xxx.com/mgmt/" 
              xmlns:ns3="http://xxx.com/list/">
    <ns2:ntfs count="140">
      <ns2:ntf>
        <ns2:Nid>4687807</ns2:Nid>
      </ns2:ntf>
    </ns2:ntfs>
  </ns3:op>
</response>

I have to read this in IE 7, IE 8 , IE 9 , FF, safari and chrome

The namespace index may not be the same and might change. I need to parse the xml independent of the namespace and browser.

I am trying to do this

var xmlDoc = new DOMParser().parseFromString(....);
xmlDoc.setProperty("SelectionNamespaces", 'xmlns:ns3="http://xxx.com/list/"');
xmlDoc.setProperty("SelectionLanguage", "XPath");
var op = xmlDoc.selectSingleNode("/response/ns3:op");

This works only in IE. Please let me know how can i parse the xml in all browsers.

Upvotes: 1

Views: 990

Answers (1)

Bergi
Bergi

Reputation: 665555

This works only in IE

Yes. setProperty is a proprietary method in MSXML (actually I didn't knew IE did support XPath at all).

For the standard solution, see MDN's article Using XPath, favouring document.evaluate. You should use feature detection to check whether it's available, and if not fall back to your document.selectSingleNode.

Upvotes: 1

Related Questions