Converting nested xml to nested html recursively

shadowgfx

New Member
I want to convert nested xml to nested ul li structure. I have written all the code but there is a error in it. I have spent whole day but can't getting it to work. The error can be very simple. Can anyone please look into that and reply to me.\[code\]<html><head> <script type="text/javascript"> var str = ""; var temp = ""; function makeTree() { treeUL = createNestedTree($('root')); $("#tree").append(treeUL); } function createNestedTree(obj) { if($(obj).children().size() != 0) { str = str + "<li>" + $(obj).attr("name") + "</li><ul>"; $(obj).children("item").each(function() { returnValue = http://stackoverflow.com/questions/11416568/createNestedTree($(this)); str = str + returnValue; }); return str +"</ul>"; } else { temp = "<li>" + $(obj).attr("name") + "</li><ul></ul>"; return temp; } } </script></head><body> <!-- xml structure start --> <root> <item name="a"> <item name="d"> <item name="d"></item> <item name="e"></item> <item name="f"></item> </item> <item name="g"></item> <item name="h"></item> </item> <item name="b"></item> <item name="c"></item> </root> <!-- xml structure end --> <a href="javascript:makeTree()">Make Tree</a> <div id="tree"></div></body></html>?\[/code\]Fiddle is hereI have created xml inside html because I do not know how to refer external xml into fiddle. But it behaves exactly like xml when passed to the function so no issues about that.
 
Back
Top