IE 11中为空的ActiveXObject(“ Microsoft.XMLDOM”) [英] Empty ActiveXObject("Microsoft.XMLDOM") in IE 11

查看:406
本文介绍了IE 11中为空的ActiveXObject(“ Microsoft.XMLDOM”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ActiveXObject( Microsoft.XMLDOM); 帮助加载我拥有的XML文件。我知道IE 11现在支持DOMparser,但在阅读此 $ c> Microsoft.XMLDOM 我必须添加 xmlDoc.setProperty( SelectionLanguage, XPath); 。我在代码中所做的唯一更改是我添加了新代码

  try {
xmlDoc.setProperty ( SelectionLanguage, XPath);
xmlNode = xmlDoc.selectNodes( // fields / data [包含(@ options,'formatcurrency')]);
}


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?

解决方案

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

这篇关于IE 11中为空的ActiveXObject(“ Microsoft.XMLDOM”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆