以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  javascript读取xml的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=41426)


--  作者:good_youth
--  发布时间:12/20/2006 2:51:00 PM

--  javascript读取xml的问题
tree.xml
[code]
<?xml version="1.0" encoding="gb2312"?>
<root>
 <channles>
   <document>
    <title>标题11</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
   <document>
    <title>标题12</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
   <document>
    <title>标题13</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
 </channles>
 <channles>
   <document>
    <title>标题21</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
   <document>
    <title>标题22</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
   <document>
    <title>标题23</title>
    <date><![CDATA[2006年12月16日]]></date>
   </document>
 </channles>
</root>

[/code]

xml-js.htm
[code]
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>
<div id="content"></div>

<script language="javascript">
function XMLTree(){

}

XMLTree.prototype = {
 
 arrNode: new Array(),
 load : function(xmlsrc){
  this.xmlsrc = xmlsrc;
  this.xmlDoc = new ActiveXObject("Msxml.DOMDocument");
  this.xmlDoc.preserveWhiteSpace = false;

  this.xmlDoc.load(xmlsrc);
 },
 
 channelTree : function(node){
  child = node.childNodes;
  if(node.hasChildNodes()){
   for (var i=0;i<child.length;i++){
    document.write(child[i].nodeName + "<br>");
    node = child[i];
    this.channelTree(node);
   }
  }
  
 }

}
var xt = new XMLTree();
xt.load("tree.xml");
xt.channelTree(xt.xmlDoc.documentElement);
</script>

</BODY>
</HTML>
[/code]
我想要这样的效果
channles1
    标题11  2006年12月16日
    标题12  2006年12月16日
    标题13  2006年12月16日

channles2
    标题21  2006年12月16日
    标题22  2006年12月16日
    标题23  2006年12月16日

我怎么遍历才能得到所有节点?请高手指点


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
9,359.375ms