Parse XML recursively using JQuery

haroldbat

New Member
\[code\]<script> $(document).ready(function(){ var xml = "<root> \ <method name='A'> \ <childcall name='B'></childcall> \ <childcall name='C'></childcall> \ </method> \ <method name='B'> \ <childcall name='D'></childcall> \ </method> \ <method name='C'> \ <childcall name='D'></childcall> \ <childcall name='E'></childcall> \ </method> \ </root>"; var data = http://stackoverflow.com/questions/15901335/$.parseXML(xml); console.log(data); $(data).find('method').each(function(){ var name = $(this).attr('name'); $('<div class="items"></div>').html('<a href="'+name+'">'+name+'</a>').appendTo('#page-wrap'); }); }); </script></head><body> <div id="page-wrap"></div></body></html>\[/code\]This code outputs A B C for parent method tag. The required output is A B C B D C D E.How do I traverse the child nodes recursively to get the required output? Would that be a depth-first-search?
 
Top