Tim
Tim

Reputation: 395

jQuery XML Traversing

I have the following XML format and would like to get the list of markers for each category using jQuery.

<categories>
    <category id="1">
        <marker />
        <marker />
        <marker />
    </category>
    <category id="2">
        <marker />
        <marker />
        <marker />
    </category>
    <category id="3">
        <marker />
        <marker />
        <marker />
    </category>
</categories>

I am loading the XML correctly using jQuery with an AJAX call and when I use jQuery.find().each I am getting anywhere. Am I doing it wrong?

$(data).find('category[id=1] > marker').each(function() {}
$(data).find('categories category[id=1] > marker').each(function() {}

Upvotes: 0

Views: 347

Answers (2)

kobe
kobe

Reputation: 15835

A sample from my code , replace the names with your code

// process your code inside the loops

 $(callback).find('CartClass Shipments Shipment Items Item').each(function() {                       
                        $(callback).find('EstimatedArrivalDate Item').each(function() {

});

                    });

Upvotes: 0

user113716
user113716

Reputation: 322462

Your first solution would be correct, except that you're missing the closing );.

Example: http://jsfiddle.net/vyFeZ/

$(data).find('category[id=1] > marker').each(function() {
    // do something
});

Upvotes: 1

Related Questions