in reply to Re: XML::Twig and paste
in thread XML::Twig and paste

Thanks mirod, I'm still not sure I understand what you mean. Do you mean I have to skip every other element for this to work right? I thought in order to print out an entire document tree you had to print out from the root, regardless of how many elements there are in the tree. I only put one element in the tree for my example; in my real program there are more. Thanks, Jezzica85

Replies are listed 'Best First'.
Re^3: XML::Twig and paste
by mirod (Canon) on Jul 25, 2007 at 16:56 UTC

    To print the document: $t->print prints the entire document. You don't have to do the inner loop yourself.

      I need to put some extra html formatting before the XML before I print it, though, and the formatting depends on the element, so I do need to do the inner loop to get each element. So, I guess I'm still kind of confused here--if paste puts in 2 elements, the actual element and its text, how do you print out the element, and not that secondary text element? Sorry if I sound like a broken record; I still don't understand. Jezzica85

        You can loop through only the "real" elements by writing next_element( '#ELT').. You could also use the start_tag and end_tag methods for "real" elements and the xml_string element for text ('#PCDATA') element.

        Alternatively, and I would reccomend that approach, you could generate the "extra html formating" as part of the document: adding attributes, inserting elements or wrapping existing elements in new ("formating") elements. Then you can output the twig (or parts of it) at once.