Using jQuery.each to cycle through an XML file

I have an XML file that is quite long. Below is the code I use to extract the file and then view the file with jQuery.each (), outputting the correct information:

$(document).ready(function(){ $.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: function(xml) { $(xml).find('Table').each(function(index){ var provider = $(this).find('Provider').text(); var channel = $(this).find('FeedCommonName').text(); var hd = $(this).find('FeedIsHD').text(); $('.box ul').append('<li>'+channel+'</li>'); }); } }); }); 

The problem I ran into is code that only gives me element 31. I added an index variable in to see this and it gives me an index from 0 to 30. So there is some kind of limitation that .each ( ) only increases to index 30, and if so, is there another way to go through the XML file? Thanks.

EDIT: Solved, at least for now. There were also an XML file that supported processing. Probably another reminder to check the source file.

+6
source share
1 answer

Try using parseXML before finding an element

 $(document).ready(function(){ $.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: function(xml) { $.parseXML(xml).find('Table').each(function(index){ var provider = $(this).find('Provider').text(); var channel = $(this).find('FeedCommonName').text(); var hd = $(this).find('FeedIsHD').text(); $('.box ul').append('<li>'+channel+'</li>'); }); }, error: function() { $('.box ul').text("Failed to get xml"); } }); }); 
+12
source

Source: https://habr.com/ru/post/895090/


All Articles