我为你写了简单的 HTML。演示在http://jsfiddle.net/UC2dM/185/
$.ajax({
url:'/echo/xml/',
data: {xml:'<Books><book><title>C++</title><author>A</author> </book><book><title>XML</title><author>X</author></book></Books>'},
dataType: 'xml',
type:'post',
success: function(data){
var xml = $(data);
$('#container').append( CategoryToUl(xml.children()) );
}
});
function CategoryToUl(xml){
var categories = xml.children('book');
if (categories.length > 0)
{
var ul = $('<ul/>');
categories.each(function(){
var $this = $(this);
var li = $('<li/>');
var a = $('<a/>',{
text: $this.children('title').text()
});
li.append(a);
li.append( CategoryToUl( $this ) );
ul.append(li);
});
return ul;
}
return null;
}