in reply to XML::Twig and paste

The problem is in the loop: the first element is the root. The you get the next element, the tag element, which you print. Its content is <tag>content</tag>, then you take the next element: this one is the text (#PCDATA') element in the tag element, and you print it. Its content is content. Then you take the next element, there is none and you exit.

So paste works, its just your understanding of next_element and print that was off.

Replies are listed 'Best First'.
Re^2: XML::Twig and paste
by jezzica85 (Initiate) on Jul 25, 2007 at 16:41 UTC
    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

      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