in reply to twig inbuilt methods to sort whole xml tree
Prints:$root->first_child->sort_children_on_att("type"); sort_my_kids($root); $twig->print; #---------- sub sort_my_kids{ my $me = shift; $me->sort_children_on_value; foreach my $kid($me->children){ sort_my_kids($kid); # Recursive } }
<enhancement> <descriptorgroup> <descriptors controlled="y" type="DRG"> <mainterm weight="a">aspirin</mainterm> <mainterm>panadol</mainterm> <mainterm>xenon</mainterm> <mainterm weight="a">zorro</mainterm> </descriptors> <descriptors controlled="y" type="MED"> <descriptor> <mainterm>disease</mainterm> <mainterm>pestilence</mainterm> <mainterm weight="a">plague</mainterm> </descriptor> </descriptors> </descriptorgroup> </enhancement>
Theory is when you know something, but it doesn't work.
Practice is when
something works, but you don't know why it works.
Programmers combine Theory
and Practice: Nothing works and they don't know why.
-Anonymous
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: twig inbuilt methods to sort whole xml tree
by bharathinc (Novice) on Mar 08, 2010 at 06:40 UTC | |
by bharathinc (Novice) on Mar 09, 2010 at 06:05 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |