Source XML looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<area>
<ticket>
<ticketnumber>001</ticketnumber>
<location>Location</location>
</ticket>
<ticket>
<ticketnumber>001</ticketnumber>
<location>Location</location>
</ticket>
<ticket>
<ticketnumber>001</ticketnumber>
<location>Location</location>
</ticket>...
</area>
I can parse this into an existing un-ordered list using the following code:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "feed.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('ticket').each(function(){
var varTicket = $(this).find('ticketnumber').text();
var varLocation = $(this).find('location').text();
var varTheHTML = '<li>'+varTicket+' '+varLocation+'</li>';
$(varTheHTML).appendTo("#ticket-test");
});
},
error: function() {
alert("The XML File could not be processed correctly.");
}
});
});
This provides me with a populated list as expected.
<ul id="ticket-test">
<li>001 Location</li>
<li>001 Location</li>
<li>001 Location</li>...
</ul>
The problems begin to arise when I need to split this list into multiple lists, ideally nested in the master list. The new structure would now be:
<ul id="ticket-test">
<li>
<ul>
<li>001 Location</li>
<li>001 Location</li>
<li>001 Location</li>...
</ul>
</li>
<li>
<ul>
<li>001 Location</li>
<li>001 Location</li>
<li>001 Location</li>...
</ul>
</li>...
</ul>
The source XML is essentially a flat list, so I need to assign these list items into chunks of, say, 10 or so (used later with unslider).
I have tried running counters within the .each function and using a return false to jump back out again, but the code quickly becomes a spaghetti junction, I'm certain there is a more elegant way of achieving this.
I've also tried .split and for loops, but keep hitting a brick wall.
<ul>duplicate of first nested<ul>?