How to Use recursive parsing xml_javascript in js

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.