I have an XML file that is pretty long. Below is the code I am using to retrieve the file and then go through the file using jQuery's .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'm having is the code only gives me up to element 31. I added the index variable in to see that, and it is giving me an index from 0 to 30. So is there some limitation that .each() only goes up to an index of 30, and if so, is there another way to go through the XML file? Thanks.
EDIT: Solved, at least for now. There were &'s in the XML file, which was holding up the processing. I guess another reminder to validate your source file first.
Try using parseXML
before you find the 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");
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With