1

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.

later2013
  • 41
  • 3
  • 3
    What are you trying to do? XML `Document` objects indeed don't have such a method. – Bergi Apr 06 '13 at 12:25
  • 1
    Why do you think a method such as `setProperty` does exist? If you explain *what* you want to do, we might be able to help you. – Felix Kling Apr 06 '13 at 12:42
  • Hi Felix,I have the below xml 4687807 – later2013 Apr 06 '13 at 18:28
  • You can use the answer provided here for cross browser XML parsing: http://stackoverflow.com/questions/7949752/cross-browser-javascript-xml-parsing, but there is nothing indicating that ``setProperty`` is working anywhere. – mzedeler Apr 06 '13 at 18:44

1 Answers1

1

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375