Home > Web Front-end > JS Tutorial > body text

js uses recursive parsing xml_javascript techniques

WBOY
Release: 2016-05-16 16:27:28
Original
2034 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template