Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript on IE9. XMLDOM.selectSingleNode gives Unknown method -->concat

Why is this code giving me the following error on IE: "Unknown Method. //author[@select = -->concat('tes'<--,'ts')]?

function a()
{
    try
    {
        var xml ='<?xml version="1.0"?><book><author select="tests">blah</author></book>';


        var doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.loadXML(xml);

        node = doc.selectSingleNode("//author[@select = concat('tes','ts')]");
        if(node == null)
        {
            alert("Node is null");
        }
        else
        {
            alert("Node is NOT null");
        }
    } catch(e)
    {
        alert(e.message);
    }
}
like image 978
Abdul Avatar asked Jul 28 '26 17:07

Abdul


1 Answers

Well Microsoft.XMLDOM is an antiquated programming id and you end up with an old MSXML version that by default does not support XPath 1.0 but rather an old, never standardized draft version. These days MSXML 6 is part of any OS or OS with latest service pack that Microsoft supports so simply consider to use an MSXML 6 DOM document with e.g.

        var xml ='<?xml version="1.0"?><book><author select="tests">blah</author></book>';

  var doc = new ActiveXObject("Msxml2.DOMDocument.6.0");
  doc.loadXML(xml);

        node = doc.selectSingleNode("//author[@select = concat('tes','ts')]");
        if(node == null)
        {
            alert("Node is null");
        }
        else
        {
            alert("Node is NOT null");
        }

If you insist on using Microsoft.XMLDOM then call doc.setProperty("SelectionLanguage", "XPath") before any selectSingleNode or selectNodes calls trying to use XPath 1.0.

like image 130
Martin Honnen Avatar answered Jul 30 '26 08:07

Martin Honnen