Here's a my quick and dirty stab at it, may or may not be what you
looking for:
function transformXML(node:XML):XML
{
if (node.name() == "target") {
[EMAIL PROTECTED]"id"]=node.text();
node.setChildren(node.parent()..*.(name()=="data"));
}
if (node.name() == "node") {
node.setName("tree");
}
var n:int=0;
var cnode:XML;
while (n < node.children().length())
{
cnode=node.children()[n];
if (cnode.name() == "data" && node.name() != "target") {
delete node.children()[cnode.childIndex()];
continue;
}
transformXML(cnode)
n++;
}
return node;
}
-- Keith H --
www.keith-hair.net
Glen Pike wrote:
Hi,
I have a load of data loaded from a server as XML which is
essentially a flat list. Nodes in the list have a child node defining
a target and many nodes have the same target.
<list>
<node><target>1</target><data>blah1</data></node>
<node><target>1</target><data>blah2</data></node>
<node><target>2</target><data>blah3</data></node>
<node><target>3</target><data>blah4</data></node>
<node><target>1</target><data>blah5</data></node>
</list>
I want to re-arrange this list into a tree structure to group the
nodes by target and use as a data provider to a tree control.
<tree>
<target id="1">
<data>blah1</data>
<data>blah2</data>
<data>blah5</data>
</target>
<target id="2">
<data>blah3</data>
</target>
<target id="3">
<data>blah4</data>
</target>
</tree>
The list can have large numbers of entries - in the order of 1000's
- are there sneaky / fast ways of manipulating the list into my tree
structure?
Thanks
Glen
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders