'Empty ActiveXObject("Microsoft.XMLDOM") in IE 11
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
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.
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?
Solution 1:[1]
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')]");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |