【问题标题】:Find Particular Node's Child Element From XML Using Jquery使用 Jquery 从 XML 中查找特定节点的子元素
【发布时间】:2013-01-29 12:57:06
【问题描述】:

我有一个类似的 xml 文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<childrens>
<child id="1" value="Root Catalog" parent_id="0">
  <child id="2" value="Apparel" parent_id="1">
  <child id="4" value="Shirts" parent_id="2"/>
<child id="5" value="Pants" parent_id="2"/>
</child>
<child id="3" value="Accessories" parent_id="1">
  <child id="6" value="Handbags" parent_id="3"/>
  <child id="7" value="Jewelry" parent_id="3"/>
</child>
 .
 .
 .
<child id='1110'>
   <child id='1111' value="test" parent_is="1110">
       <child id="1005" value="test1" parent_is="1111"/>
       <child id="1006" value="test12" parent_is="1111"/>
       <child id="1007" value="test123" parent_is="1111"/>
    <child>
</child>
<child >
</childrens>

我正在使用 jquery 来查找特定节点的子节点

我编写了这段代码来查找id=1111value=test 所在节点的子节点

$(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "test.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('child[value="test"]').each(function(){
                var i = $(this).attr('value');
                alert(i);

            });
        }
    });
});

它只给了我一个名字,那就是它自己

虽然我需要输出三个名称,这是它的子元素

这是test1tets12test123

【问题讨论】:

    标签: jquery xml ajax


    【解决方案1】:

    我想你想使用.children()

    $(xml).find('child[value="test"]').children().each(function(){
        ...
    });
    

    【讨论】:

      猜你喜欢
      • 2011-07-06
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多