This library does all the work for you:
http://www.openjsan.org/doc/k/ka/kawasaki/XML/ObjTree/0.24/lib/XML/ObjTree.html
var js = (new XML.ObjTree).parse("0");
Then you have a JavaScript tree and you can display it however you want. You might want to try the YAHOO.widget.TreeView module for that it will create a "expandable and collapsible tree." That is if you like the YUI library, other wise there is Dojo and Ext libraries that can create a treeview for you.