From: Klaus on
On 26 avr, 23:58, s...(a)netherlands.com wrote:
> my $buffer = '';
>
> while ($rdr->iterate) {
>    $buffer .= $rdr->rval;
>
> }
>
> if (length $buffer) {
>    my $ref = XMLin('<FileItem>'.$buffer.'</FileItem>');
>    print Dumper($ref), "\n\n";
>
> }

If memory is not important, than you can use use XML::Reader 0.34
qw(slurp_xml):

use strict;
use warnings;
use XML::Reader 0.34 qw(slurp_xml);

use XML::Simple;
use Data::Dumper;

my $root = '/Data/ConnectionList/Connection/FileItemList/FileItem/
FileType';
my $lref = slurp_xml(\*DATA, {root => $root, branch => '*'});
my $buffer = join '', map {$$_} @{$lref->[0]};
my $ref = XMLin("<Item>$buffer</Item>");

print Dumper($ref), "\n\n";
From: Klaus on
On 27 avr, 02:01, John Bokma <j...(a)castleamber.com> wrote:
> Klaus <klau...(a)gmail.com> writes:
> > my $rdr = XML::Reader->newhd(\*DATA, {filter => 5},
>
> To me filter is very unclear. I understand that it are options to the
> program, but just 5 is very confusing. Maybe split "filter" in several
> options which combined result in 1,2,3,4,5 ?

"filter => 2,3,4,5" is just a construction that has historically grown
inside XML::Reader.

But I agree very much with you, I also find that "filter => 2,3,4,5"
is not expressive at all. I will think of a better way to select the
mode of operation for XML::Reader.

> why is the constructor called newhd?

Thanks for the question.

That, again, is a historic accident. ==> Back in the old days of
XML::Reader ver 0.01, there used to be an option {filter => 1} and the
constructor back then was called new() and defaulted to {filter => 1}.

Then, in version 0.03 (or so) I decided to have the constructor
default to {filter => 2}, but I didn't want to break code that already
used the old default, so I came up with a second constructor called
newhd() that defaults to {filter => 2}.

At some version of XML::Reader the {filter => 1} and its use of the
constructor new() had disappeared. Therefore it is possible now to
rename newhd() back into new(). I think I will go back to constructor
new() in a future version of XML::Reader.
From: Klaus on
On 27 avr, 09:10, Klaus <klau...(a)gmail.com> wrote:
> On 27 avr, 02:01, John Bokma <j...(a)castleamber.com> wrote:
>
> > Klaus <klau...(a)gmail.com> writes:
> > > my $rdr = XML::Reader->newhd(\*DATA, {filter => 5},
>
> > To me filter is very unclear. I understand that it are options to the
> > program, but just 5 is very confusing. Maybe split "filter" in several
> > options which combined result in 1,2,3,4,5 ?
>
> I will think of a better way to select the
> mode of operation for XML::Reader.
>
> > why is the constructor called newhd?
>
> [...] I think I will go back to constructor
> new() in a future version of XML::Reader.

I have now released a new version of XML::Reader (ver
0.35) with some bug fixes, warts removed, relicensing, etc...
http://search.cpan.org/~keichner/XML-Reader-0.35/lib/XML/Reader.pm

The line I wrote in my previous post (which was for XML::Reader ver
0.34) was:

my $rdr = XML::Reader->newhd(\*DATA, {filter => 5},

With the new version 0.35 of XML::Reader, the same line would be
spelled:

my $rdr = XML::Reader->new(\*DATA, {mode => 'branches'},