xml吧 关注:2,093贴子:5,879
  • 0回复贴,共1

xml DOM遍历元素

只看楼主收藏回复

<html>
    <head>
        <SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="ONLOAD">
            var xmldoc=xmldso.XMLDocument;
            xmldoc.load("dom_1.xml");
            var xmls=xmldoc.documentElement;
            var resulstr="";
            outtext.innerText=seektitle(xmls,0);

        function seektitle(node,level){
            var str="";
            if(nodeName=='title'){
                var space="";
                for(i=0;i<level;i++)
                    space+=" ";
                str=space+node.Text;
            }
            var childs=node.childNodes;
            if(childs!=null){
                for(i=0;i<childs.length;i++)
                    str+=seektitle(childs(i);level+1);
            }
            return str;
        }

        </SCRIPT>
    </head>
    <body>
        <OBJECT width=0 height=0 classid="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" id="xmldso">
        <span id="outtext"></span>
    </body>
</html>
///////////////////////////////////////////////
<?xml version="1.0" encoding="gb2312"?>
<directory>
<chapter>
<title>述</title>
<content>text1-0-0.htm</content>
<section>
<title>介</title>
<content>text1-1-0.htm</content>
</section>
<section>
<title>历</title>
<content>text1-2-0.htm</content>
</section>
<section>
<title>置标语言分类及比较</title>
<content>text1-3-0.htm</content>
<question>
<title>置标语言分类</title>
<content>text1-3-1.htm</content>
</question>
<question>
<title>从HTML到XHTML</title>
<content>text1-3-2.htm</content>
</question>
</section>
<section>
<title>XML和HTML</title>
<content>text1-4-0.htm</content>
</section>
<section>
<title>XML的Web应用</title>
<content>text1-5-0.htm</content>
</section>
<section>
<title>XML知识体系结构</title>
<content>text1-6-0.htm</content>
</section>
</chapter>
<chapter>
<title>XML基本语法</title>
<content>text2-0-0.htm</content>
<section>
<title>XML的语法规则</title>
<content>text2-1-0.htm</content>
</section>
<section>
<title>XML文档的组成</title>
<content>text2-2-0.htm</content>
</section>
</chapter>
</directory>




1楼2007-06-07 13:51回复