You can do this recursively.
But you need your xml to have the root root.
here is a function for your specifications (this is the core of jQuery, so I assume the mobile version will handle it)
function CategoryToUl(xml){
var categories = xml.children('category');
if (categories.length > 0)
{
var ul = $('<ul/>');
categories.each(function(){
var $this = $(this);
var li = $('<li/>');
var a = $('<a/>',{
text: $this.children('title').text(),
href: '#' + $this.children('catId').text()
});
li.append(a);
li.append( CategoryToUl( $this ) );
ul.append(li);
});
return ul;
}
return null;
}
and here's what to call it
$.ajax({
url:'path-to.xml',
dataType: 'xml',
success: function(data){
var xml = $(data);
$('#container').append( CategoryToUl(xml.children()) );
}
});
demo at http://www.jsfiddle.net/gaby/UC2dM/1/
He creates a structure like this
<ul>
<li><a href="#96">News</a></li>
<li><a href="#97">Articles</a>
<ul>
<li><a href="#101">Destinations</a></li>
<li><a href="#102">Epics</a></li>
</ul></li>
<li><a href="#129">Tuesday Night Bouldering</a></li>
</ul>
source
share