I am extracting a bunch of data from an XML file using jQuery. I need to use the data to fill in image paths, names, etc.
What is the best way to gather all of this data for use? For instance, I get everything like so:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "stuff.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('speaker').each(function(){
var img_path = $(this).find('speaker_image').text();
var name_text = $(this).find('speaker_name').text();
// should I build an array or object here?
});
}
});
});
Should I stick everything into an array in the success method? Maybe in an object? What I will do is take the collected data and use it to build a list of names and images. There will be quite a few elements in this and it will look something like (with img_path being used in the image url and name_text being used for the label:
<ul>
<li><img src="images/bobsmith.jpg" /><br /><lable>Bob S. Smith</label></li>
<li><img src="images/crystalforehead.jpg" /><br /><lable>Crystal X. Forehead</label></li>
...
</ul>
What is the best way to handle the collected data so I can go through and build the html I need using it?