M.I.T.
M.I.T.

Reputation: 1042

Find Particular Node's Child Element From XML Using Jquery

i have a xml file like

<?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>

i am using jquery to find a particular nodes children

i have written this code to find the child of the node where id=1111 and value=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);

            });
        }
    });
});

it gives me only one name which is it self

while i need in output three name which is its child element

which is test1, tets12, test123

Upvotes: 0

Views: 8861

Answers (1)

Alexander
Alexander

Reputation: 23537

I suppose you want to use .children().

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

Upvotes: 3

Related Questions