您好,欢迎访问一九零五行业门户网

js使用递归解析xml_javascript技巧

xml结构:
复制代码 代码如下:
解析方法:
复制代码 代码如下:
$(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;
    };
以上就是javascript使用递归解析xml的全部代码了,超级简洁,非常使用,给需要的小伙伴参考下。
其它类似信息

推荐信息