⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 16-9.htm

📁 有关JAVASCRIPT的源代码教程
💻 HTM
字号:
    <html><head><title>分析XML文档</title> 
        <xml ID="xml1" SRC="16-2.xml"></xml> 
        <script language="JavaScript"> 
           <!--
           function parseDocument(){ 
              var documentXML = document.all("xml1").XMLDocument; 
              div1.innerHTML = parse(documentXML, ""); 
           } 
           function parse(node1, indent){ 
             var type; 
             switch (node1.nodeType) { 
               case 1: 
                 type = "元素"; 
                 break; 
               case 2: 
                 type = "属性"; 
                 break; 
               case 3: 
                 type = "文字"; 
                 break; 
               case 4: 
                 type = "CDATA节"; 
                 break; 
               case 5: 
                 type = "实体引用"; 
                 break; 
               case 6: 
                 type = "实体"; 
                 break; 
               case 7: 
                 type = "处理指令"; 
                 break; 
               case 8: 
                 type = "注释"; 
                 break; 
               case 9: 
                 type = "文档"; 
                 break; 
               case 10: 
                 type = "文档类型"; 
                 break; 
               case 11: 
                 type = "文档分段"; 
                 break; 
               case 12: 
                 type = "符号"; 
             } 
             var text; 
             if (node1.nodeValue != null) { 
                text = indent + node1.nodeName 
                     + "&nbsp; = " + node1.nodeValue 
                     + "&nbsp; (节点类型: " + type + ")"; 
             } 
             else { 
               text = indent + node1.nodeName 
                          + "&nbsp; (节点类型: " + type + ")" ;
             } 
             if (node1.attributes != null) { 
               if (node1.attributes.length > 0) { 
                 for (var loopIndex = 0; loopIndex < 
                   node1.attributes.length; loopIndex++) { 
                   text += " (属性: " + 
                        node1.attributes(loopIndex).nodeName + 
                        " = \"" + 
                        node1.attributes(loopIndex).nodeValue + "\")" ;
                 } 
               } 
             } 
             text += "<BR>" ;
             if (node1.childNodes.length > 0) { 
               for (var loopIndex = 0; loopIndex < 
                  node1.childNodes.length; loopIndex++) { 
                  text += parse(node1.childNodes(loopIndex), 
                  indent + "&nbsp;&nbsp;") ;
               } 
             } 
             return text ;
        } 
        //--> 
        </script> 
        </head> 
       <body><h1>分析XML文档</h1> 
          <input type="button" value="解析XML文档" 
            onclick="parseDocument()"> 
          <div ID="div1"></div> 
       </body> 
    </html> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -