Thanks Ouato,
I think I might have explained that a little badly, basically what I'm trying to do is add a button on a web page before each element and before each of its children, so basically I want to see the tree in series, with a button, then the first element, a button, then the first child of the first element, etc.
How would you go about removing and storing the nested children? Would that slow the program down a lot?
Also, I just found out that I'm getting this error about an element already being present in the tree, does that mean that an XML tree can't have duplicate elements, or that the IDs are the same?
Thanks for bearing with my rambling. :)
Jezzica85 | [reply] |
foreach my $elt ($twig->root->descendants( '#ELT'))
{ $elt->insert_new_element( 'before', button => { attribute });}
$twig->print;
Of course the simple answer to your question is that the xml_text_only (I hate that name!) method would do it. But really, don't use it. | [reply] [d/l] |
Okay, I think I understand.
I think the best solution is to add a "button" element as the first child of each element of the tree you want to display with a button.
When printing, the first element to be displayed after your 'element' will be its button, and then the other childs.
And yes, my 'solution' was bad and would have sensibly slow down the page.
For your error, you are probably trying to add the same 'reference', meaning you don't create a new element before adding it, you only 'edit' the old one properties and try to add it again, but i'm not used to XML::Twig and I didn't see your code.
| [reply] |