posts - 297,  comments - 1618,  trackbacks - 0

Amigo(33056009) 17:46:48
问个问题
若我的xml的内容如下:

<response>
    
<option>
        
<value>0< alue>
        
<textContent>xxx</textContent>
    
</option>
    
<option>
        
<value>1< alue>
        
<textContent>yyy</textContent>
    
</option>
</response>

 

我已取到options数组了,alert出options的长度是2,我想遍历取得各数组中的value和textContext,该怎么写js啊

告诉我个关键字去google也好
BeanSoft(9991483) 17:46:50
哈,去看看 xloadtree 的实现即可
Amigo(33056009) 17:48:01

 
BeanSoft(9991483) 17:47:52
  // there is one extra level of tree elements
  var root = oXmlDoc.documentElement;

  // loop through all tree children
  var cs = root.childNodes;
  var l = cs.length;
  for (var i = 0; i < l; i++) {
   if (cs[i].tagName == "tree") {
    bAnyChildren = true;
    bIndent = true;
    jsParentNode.add( _xmlTreeToJsTree(cs[i]), true);
   }
  }
BeanSoft(9991483) 17:48:03
// Converts an xml tree to a js tree. See article about xml tree format
function _xmlTreeToJsTree(oNode) {
 // retreive attributes
 var text = oNode.getAttribute("text");
 var action = oNode.getAttribute("action");
BeanSoft(9991483) 17:48:27
<?xml version="1.0"?>

<tree>
 <tree text="Load &quot;tree1.xml&quot;" src="tree1.xml" />
 <tree text="Loaded Item 1" action="http://webfx.eae.net" />
 <tree text="Loaded Item 2">
  <tree text="Loaded Item 2.1" action="javascript:alert(2.1)" />
 </tree>
 <tree text="Loaded Item 3 (with target)" action="http://www.google.com" target="_new" />
 <tree text="Load &quot;tree1.xml&quot;" src="tree1.xml" />
</tree>

Amigo(33056009) 17:49:41
多谢

问题解决,修改后的js如下:

var options = http_request.responseXML.getElementsByTagName("option");
                
var value = new Array();
                
var textContent = new Array();

                
for (var i = 0; i < options.length; i++){
                    
var cn = options[i].childNodes; 
                    
var len = cn.length;
                    
for (var j = 0; j < len; j++{
                        
if (cn[j].tagName == "value"{
                            value[i] 
= cn[j].firstChild.data;
                        }
 else if(cn[j].tagName == "textContent"{
                            textContent[i] 
= cn[j].firstChild.data;
                        }

                    }

                }


       感谢bean老大,嘻嘻,解决问题。
posted on 2007-04-04 18:03 阿蜜果 阅读(1052) 评论(3)  编辑  收藏 所属分类: Javascript


FeedBack:
# re: 取得xml某节点的子节点----问与答
2007-04-05 02:52 | cresposhi
这种东西不问我可惜了可惜了,嘿嘿  回复  更多评论
  
# re: 取得xml某节点的子节点----问与答[未登录]
2007-04-05 08:54 | 阿蜜果
晕,你都把群信息屏蔽了,本来就是想问你--js king的
啊哈  回复  更多评论
  
# re: 取得xml某节点的子节点----问与答
2007-04-05 09:07 | cresposhi
太吵了,没办法。。。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

      生活将我们磨圆,是为了让我们滚得更远——“圆”来如此。
      我的作品:
      玩转Axure RP  (2015年12月出版)
      

      Power Designer系统分析与建模实战  (2015年7月出版)
      
     Struts2+Hibernate3+Spring2   (2010年5月出版)
     

留言簿(262)

随笔分类

随笔档案

文章分类

相册

关注blog

积分与排名

  • 积分 - 2279799
  • 排名 - 3

最新评论

阅读排行榜

评论排行榜