0

I am using ActiveXObject("Microsoft.XMLDOM"); to help loadan XML file that I have. I know that IE 11 now support DOMparser, but after reading this stack mover flow post it seems that IE 11 still support Active X also. So as suggested I have this code

try {               
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            console.log(xmlDoc);
            xmlDoc.async = false;
            console.log(xml);
            xmlDoc.loadXML(xml);

            return xmlDoc;
        } catch (e) {
            console.log(e);               
            try {
                var parser = new DOMParser();
                xmlDoc = parser.parseFromString(xml, "text/xml");               
                return xmlDoc;
            }catch(e) {
                console.log(e); //Tesitng for error in chrome
            }                
        }     

The problem is that in Active X object is empty

enter image description here

Did I do something wrong? Forgot to set something up? Or did IE 11 stop supporting Active X object in newer version? I would love to use the DOM parser but IE does not support XPathResult

Edit

@Teemu says that the ActiveXObj does not have a toString() further down my code is

//the function loadXMLDocStr calls the above code
var xmlDoc = GenFunctions.loadXMLDocStr(theXml); 
        var xmlNode;          
        try {              
            xmlNode = xmlDoc.selectNodes("//tfields/data[contains(@options, 'formatcurrency')]");               
        } catch (e) {               
            var listofNode;
            listofNode = xmlDoc.evaluate("//fields/data[contains(@options, 'formatcurrency')]", xmlDoc, null, XPathResult.ANY_TYPE, null);               
            xmlNode = new Array();                
            var node = listofNode.iterateNext();
            while (node) {                    
                xmlNode.push(node);
                node = listofNode.iterateNext();
            }               
        }           
        GenFunctions.populateSelect("field", xmlNode, "name", "col", true, "description", null);
    }

and the result is the above but this time I included the error about the XPATHResult. enter image description here

As you can see it is successfully creating the Active X object, but when I call the selectNode it errors out and try to call the code meant for the DOMParser using the XPATHResult So why is it that the Active X object is Empty?

Community
  • 1
  • 1
Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • 1
    Well IE11 supports the DOMParser so that should work.... – epascarello Jul 02 '14 at 16:43
  • @epascarello The problem is that IE does not support `XPATHResult`, which I need in order to get nodes from the XML if I am using the `DOMParser` – Jack Thor Jul 02 '14 at 16:47
  • Notice, that ActiveXs usually don't have `toString()` method, and they might not be enumerable (at least by any JS method), hence you can't examine their properties using console. – Teemu Jul 02 '14 at 17:01
  • @Teemu Makes sense. I will expand on the question to better reflect certain problem. – Jack Thor Jul 02 '14 at 17:03

1 Answers1

0

Found the answer here appearently if I want to use Microsoft.XMLDOM I have to add xmlDoc.setProperty("SelectionLanguage", "XPath");. The only thing I changed in my code was that I added teh new piece of code

try {
            xmlDoc.setProperty("SelectionLanguage", "XPath");
            xmlNode = xmlDoc.selectNodes("//fields/data[contains(@options, 'formatcurrency')]");                
        }
Community
  • 1
  • 1
Jack Thor
  • 1,554
  • 4
  • 24
  • 53