XML parsing + array manipulation issue
I'm having trouble here reading a list of devices from an XML (all entries in <device></device> in a main <devices> list), putting each item into an array, sorting the array, and spitting the items back out in a table cell.
I'm not sure what the issue is here, but the items don't show up at all on the page.
-
$(function() {
$.ajax({
type: "GET",
url: "list.xml",
dataType: "xml",
success: function(xml)
{
// create array for the devices
var device_array = [];
// iterate through the xml and add the devices to the array
$(xml).find('device').each(function(){
var device_name = ($this).text()
device_array.push(device_name);
});
// sort the array
device_array.sort();
// iterate through and print the elements
for (var i = 0, item; item = device_array[i]; i++) {
$('<tr><td class="device_name"></td></tr>')
.html(item)
.appendTo('#devicelist');
};
}
});
});
[/code]