IE下面解析xml文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
</head>
<body>
<script type="text/javascript">
    function getXMLDoc() {
        if (window.ActiveXObject) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLDOM");
            }
            catch (e) {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        } else {
            xmlhttp=document.implementation.createDocument('http://untitled.newsicom.com:9090/javascript2/readXML.html','aaa',null);
        }
        return xmlhttp;
    }
   // var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
    var xmlDoc=getXMLDoc();
    function loadXML(xmlFile) {
        xmlDoc.async = 'false';
        xmlDoc.onreadystatechange = verify;
        xmlDoc.load(xmlFile);
    }

    function verify() {
        if (xmlDoc.readyState !== 4) {
            return false;
        }
    }

    //开始遍历

    function traverse(tree) {
        if (tree.hasChildNodes()) {
            frames[0].document.write("<ul><li>");
            frames[0].document.write('<b>' + tree.tagName + ':</b>');
            var nodes = tree.childNodes.length;
            for (var i = 0; i < tree.childNodes.length; i++) {
                traverse(tree.childNodes[i]);
            }
            frames[0].document.write('</li></ul>');
        }
        else {
            frames[0].document.write(tree.text);
        }

    }

    function initTraverse(file) {
        loadXML(file);
        var doc = xmlDoc.documentElement;
        traverse(doc);
    }


</script>
<input id='_xmlFIle' type="file" style="width: 360"/>
<button onclick="initTraverse(_xmlFIle.value)">载入</button>
<br>
<iframe width="400" height="450"></iframe>
</body>
</html>

你可能感兴趣的:(html,xml,function,IE,File,tree)