JavaScript on IE9. XMLDOM.selectSingleNode gives an Unknown Method & # 8594; concat

Why does this code give me the following error in 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);
    }
}
+3
source share
1 answer

Well Microsoft.XMLDOM, this is an outdated programming identifier, and you get the old version of MSXML, which does not support XPath 1.0 by default, and the old, never standardized version. Nowadays, MSXML 6 is part of any OS or OS with the latest service pack that Microsoft supports, so just consider using an MSXML 6 DOM document, for example,

        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");
        }

Microsoft.XMLDOM, doc.setProperty("SelectionLanguage", "XPath") selectSingleNode selectNodes, XPath 1.0.

+5

All Articles