"Quick and dirty" often turns to "slow and messy". For example, compare the two "test" scripts in this thread. ;)

Using XML::TreeBuilder was "Quick and dirty". A XML::Twig solution is likely to be more appropriate for a scalable solution. Consider:

#! /bin/perl -w use strict; use warnings; use XML::Twig; my $dataCount = 0; my $str = do {local $/; <DATA>}; my $t= XML::Twig->new (twig_roots => {data => \&data}); $t->parse ($str); sub data { my ($t, $data) = @_; ++$dataCount; print "Data node $dataCount\n"; my @strings = $data->descendants ('string'); print " ", $_->trimmed_text (), "\n" for @strings; } __DATA__

using the same data as the previous sample orints:

Data node 1 1 some stuff 1 some more stuff 1 yet more stuff 1 enough stuff Data node 2 2 some stuff 2 some more stuff 2 yet more stuff 2 enough stuff Data node 3 3 some stuff 3 some more stuff 3 yet more stuff 3 enough stuff

Note that both samples cheat by wrapping a root element around the data elements to form a more compliant XML document.


DWIM is Perl's answer to Gödel

In reply to Re^3: Premature End-of-File - Scope problems? by GrandFather
in thread Premature End-of-File - Scope problems? by bratwiz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.