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;  
        }
    }
  • 相关阅读:
    线性代数12.图和网络
    【转载】STM32之中断与事件---中断与事件的区别
    头文件重复包含(转)
    C语言位操作
    NOP使用注意事项
    头文件intrins.h的用法
    RAM、SRAM、SDRAM、ROM、EPROM、EEPROM、Flash存储器概念
    const在C语言中的用法
    volatile的作用
    absacc.h keil软件里怎么找不到 ,如何找?
  • 原文地址:https://www.cnblogs.com/zhaoguo435/p/2258429.html
Copyright © 2011-2022 走看看