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.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn