Home >Web Front-end >JS Tutorial >js uses recursive parsing xml_javascript techniques

js uses recursive parsing xml_javascript techniques

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:27:282103browse

xml structure:

Copy code The code is as follows:











Analysis method:

Copy code The code is as follows:

$(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