AlexKunin Developer
Joined: 03 Jan 2003 Posts: 1191
|
Posted: Thu Jul 17, 2003 8:18 pm Post subject: |
|
|
Not sure if I understand your aims, but here is a sample. Function "toXML" probably is what you want. You can paste whole code into new .html file and test it with your browser.
| Code: | <script type="text/javascript">
var TREE_NODES = [
['Scripts', null, null,
['COOLjsTree', "http://javascript.cooldev.com/scripts/cooltree/", null],
['COOLjsMenu', "http://javascript.cooldev.com/scripts/coolmenu/", null],
],
['Online help', null, null,
['COOLjsTree', "http://javascript.cooldev.com/scripts/cooltree/docs/", null],
['COOLjsMenu', "http://javascript.cooldev.com/scripts/coolmenu/docs/", null],
],
['Download', null, null,
['Free', null, null],
['Order', null, null],
]
];
function toXML(nodes, prefix) {
function attr(v) { return '"' + ('' + v).replace(/"/, '&') + '"'; }
var s = '';
if (!prefix) {
s += '<?xml version="1.0" encoding="utf-8" ?>\n<tree>\n';
s += toXML(nodes, ' ');
s += '</tree>\n';
} else {
for (var i = 0; i < nodes.length; i++) {
if (!nodes[i]) continue;
var children = nodes[i].slice(3);
s += prefix + '<node';
if (nodes[i][0]) s += ' caption=' + attr(nodes[i][0]);
if (nodes[i][1]) s += ' url=' + attr(nodes[i][1]);
if (nodes[i][2]) s += ' target=' + attr(nodes[i][2]);
if (children.length) {
s += '>\n';
s += toXML(children, prefix + ' ');
s += prefix + '</node>\n';
} else
s += ' />\n';
}
}
return s;
}
var xml = toXML(TREE_NODES);
document.write('<pre>' + xml.replace(/</g, '&').replace(/>/g, '&') + '</pre>');
</script> |
For me it works like this:
| Code: | <?xml version="1.0" encoding="utf-8" ?>
<tree>
<node caption="Scripts">
<node caption="COOLjsTree" url="http://javascript.cooldev.com/scripts/cooltree/" />
<node caption="COOLjsMenu" url="http://javascript.cooldev.com/scripts/coolmenu/" />
</node>
<node caption="Online help">
<node caption="COOLjsTree" url="http://javascript.cooldev.com/scripts/cooltree/docs/" />
<node caption="COOLjsMenu" url="http://javascript.cooldev.com/scripts/coolmenu/docs/" />
</node>
<node caption="Download">
<node caption="Free" />
<node caption="Order" />
</node>
</tree> |
|
|