xml structure:
Analysis method:
$(xml).find("RightMenuItems").each(function () {
This.data = Traversal($(this).children());
});
var Traversal = function (nodes) {
var itemList = new Array();
$.each(nodes, function () {
var entity = new RightMenuEntity();
var obj = $(this);
entity.Code = obj[0].getAttribute("Code");
entity.Name = obj[0].getAttribute("Name");
entity.GroupCode = obj[0].getAttribute("GroupCode");
entity.GroupName = obj[0].getAttribute("GroupName");
If (obj[0].hasChildNodes()) entity.ChildItems = Traversal(obj.children());
ItemList.push(entity);
});
return itemList;
};
The above is the entire code for JavaScript to use recursion to parse XML. It is super concise and very useful. Please refer to it for friends who need it.