Having trouble parsing XML with jQuery

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-06-02T15:12:52Z Indexed on 2010/06/02 15:23 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

Hi Guys,

I'm trying to parse some XML data using jQuery, and as it stands I have extracted the 'ID' attribute of the required nodes and stored them in an array, and now I want to run a loop for each array member and eventually grab more attributes from the notes specific to each ID.

The problem currently is that once I get to the 'for' loop, it isn't looping, and I think I may have written the xml path data incorrectly. It runs once and I recieve the 'alert(arrayIds.length);' only once, and it only loops the correct amount of times if I remove the subsequent xml path code.

Here is my function:

    var arrayIds = new Array();
$(document).ready(function(){
  $.ajax({
    type: "GET",
    url: "question.xml",
    dataType: "xml",
    success: function(xml)
    {
                  $(xml).find("C").each(function(){
                        $("#attr2").append($(this).attr('ID') + "<br />");
                        arrayIds.push($(this).attr('ID'));
                  });

                  for (i=0; i<arrayIds.length; i++)
                  {
                    alert(arrayIds.length);
                    $(xml).find("C[ID='arrayIds[i]']").(function(){
                        // pass values
                        alert('test');
                    });
                  }
    }
  });
});

Any ideas?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery