zoukankan      html  css  js  c++  java
  • js读取本地xml文件 兼容IE Firfox Chrome 等浏览器

    var isIE = document.all;
    if(isIE)
    {
        var oXmlDom = new ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
        var oXmlDom = document.implementation.createDocument("","",null);
        Element.prototype.selectNodes = function(sXpath){
            var oEvaluator = new XPathEvaluator();
            var oResult = oEvaluator.evaluate(sXpath,this,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
            var aNodes = new Array;
            if(oResult!=null)
            {
                var oElement = oResult.iterateNext();
                while(oElement)
                {
                    aNodes.push(oElement);
                    oElement = oResult.iterateNext();
                }
            }
            return aNodes;
            
        };        
    }
    if(!oXmlDom)oXmlDom = new ActiveXObject("Microsoft.XMLDOM");
            
    function loadXML()
    {
        try{
            oXmlDom.async="false" 
            if(isIE)
            {
                oXmlDom.setProperty("SelectionLanguage","XPath");
            }
            oXmlDom.load("/XML/City.xml");
        }
        catch(e)
        {
            var xhr = new XMLHttpRequest();  
            xhr.open("GET", "/XML/City.xml", false);  
            xhr.send(null);  
        
            oXmlDom = xhr.responseXML;  
        }
    }
  • 相关阅读:
    初级算法
    初级算法
    LeetCode刷题
    win32
    Hexo
    网络上收集的C++常见面试题
    Direct2D CreateBitmap的使用
    hdu4560 不错的建图,二分最大流
    hdu4560 不错的建图,二分最大流
    poj1182 and 携程预赛2第一题 带权并查集
  • 原文地址:https://www.cnblogs.com/zhaoguo435/p/2258429.html
Copyright © 2011-2022 走看看