This article mainly introduces the use of recursive parsing xml in js. For more information about the xml structure, see:
The Code is as follows:
Resolution method:
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 all the code for parsing XML using recursion in javascript. It is super simple and very useful. Please refer to it for your reference.