Home > DeveloperSection > Forums > jQuery get multiple nodes with same name in xml
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    November-06-2014 12:59 AM

 XML AJAX  JQuery  JavaScript 
Ratings:


 1 Reply(s)
 737  View(s)
Rate this:

I have a part of an XML file that looks like this:

<paymentTypes>
<paymentType>type1</paymentType>
<paymentType>type2</paymentType>
<paymentType>type3</paymentType>
<paymentType>type4</paymentType>
</paymentTypes>

The thing is that I want to get it via ajax jQuery, but if I try this:

var paymentTypes = $(xml).find("paymentTypes").text() 

the output will be type1type2type3type4.

What function should I use(built-in or should I write it) in order to get the results on separate lines?



Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    November-06-2014 3:14 AM

u can iterate over the result append to new string

var xml ='<paymentTypes><paymentType>type1</paymentType><paymentType>type2</paymentType><paymentType>type3</paymentType><paymentType>type4</paymentType></paymentTypes>';

 

var result = "";

$(xml).find('paymentType').each(function(i,v){

    result += $(v).text()+'\n';

});

console.log(result);


Modified On Nov-06-2014 03:26:38 AM

Don't want to miss updates? Please click the below button!

Follow MindStick