PDA

View Full Version : tree to xml exporter



saxxiboy
5 Jun 2007, 2:12 AM
Hi, i'm trying to create a simple direct xml exporter in js.
Unfortunately my code isn't fully working, where am I wrong??!

any help is appriciated

Sax

<script>
/*
from:
Root
|_ a
| |_ b
| |_ c
|_ d

I would something like:
<node title="Root">
....<node title="a">
........<node title="b"></node>
........<node title="c"></node>
....</node>
....<node title="d"></node>
</node>
*/

function tree2xml(node) {
var resultNode = document.createElement('p');
resultNode.setAttribute("title",node.text);

var childs = node.childNodes;
for (var i = 0; i < childs.length; i++) {
var childEl=tree2xml(childs[i]);
resultNode.appendChild(childEl);
}
return resultNode;
}

alert(tree2xml(tree.root).innerHTML);

</script>

Animal
5 Jun 2007, 3:39 AM
http://extjs.com/forum/showthread.php?t=2516&page=4

saxxiboy
5 Jun 2007, 9:56 AM
the toXML code you provided in this thread was perfect and really easy:
http://extjs.com/forum/showthread.php?t=2516
unfortunately i was trying for almost 2 days.. (i'm not so familiar with js classes)

thanks again, :)
Sax