Recursively build an unordered list:
function xmlParser($xml) {
var $ul = $("<ul>");
$xml.contents().each(function (i, el) {
if (el.nodeType == 3) return true;
if (el.nodeName.toUpperCase() == "CHILDREN") {
$("<li>").text($(el).text()).appendTo($ul);
} else {
$ul.append(xmlParser($(el)));
}
});
return $ul;
}
Here is the demo . Think of each group and the corresponding as a separate block. For example, if your XML looked like this: ParentChildren
<Parent>Director
<Children>Exe Director1</Children>
<Children>Exe Director2</Children>
</Parent>
The result is HTML:
<ul>
<li>Exe Director1</li>
<li>Exe Director2</li>
</ul>
? : <ul>, Children <li>. , , Parent, <ul> , , <ul>.
, , , , jQuery , success:
success: function (xml) {
xmlParser($(xml));
}