hockeybpr25
hockeybpr25

Reputation: 39

jQuery XML parse with multiple instances of same tag within parent tag

Trying to get specific tag from an XML message that looks like:

<Output>
 <Name>FirstName</Name>
 <value>FirstValue<value/>
 <Name>SecondName</Name>
 <value>SecondValue</value>
</Output>

What I'm looking to do is to get the value of the second tag. If I do something like result = $(XML).find("value").text(); it lumps them together like FirstValueSecondValue. I've tried using .Children() and .filter() as well but to no avail.

Just a note. I unfortuntlely have to get this working in 1.4.2 (I know, so outdated).

I appreciate any help anyone can offer.

Upvotes: 0

Views: 554

Answers (2)

Prabhat jha
Prabhat jha

Reputation: 519

$(xml).find('Output').each(function(){    

    $values=$(this).find("value");
        $.each($values, function() {
          alert($(this).text()) ;
          });

)};

This will work,

Upvotes: 0

Leta
Leta

Reputation: 111

An answer in case anyone stumbles across this question in a search:

$(xml).find("value").eq(1).each(function(){
   console.log($(this).text());
});

For more information: http://api.jquery.com/eq/

Upvotes: 1

Related Questions