"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.
In reply to Re^3: Premature End-of-File - Scope problems?
by GrandFather
in thread Premature End-of-File - Scope problems?
by bratwiz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |