[Israel.pm] XML processing problem
Offer Kaye
oferk at oren.co.il
Thu Jun 10 05:03:48 PDT 2004
>
> Hello,
>
> Please consider the following code snippet:
>
> use XML::Twig;
>
> my $twig=XML::Twig->new(
> twig_roots => {
> item => \&handle_item
> },
> twig_print_outside_roots => 0,
> keep_encoding =>1,
> );
> $twig->parsefile( 'myfile.xml' );
> $twig->flush; # flush the end of the document
>
> sub handle_item {
> my( $twig, $item)= @_;
> # do something with $item
> }
>
>
> I was surprised to see that this code prints *some* of my
> XML file, although
> twig_print_outside_roots => 0
>
> Moreover, it seems that all the file is being processed and
> only then output (the output I don't even want) is being
> printed to the standard output. This is although this method
> should be processing the XML one 'item' at a time without
> building the twig of the whole xml file.
>
> Any ideas what's going on?
>
>
> --
> Shlomo Yona
You're using "twig_roots" together with "twig_print_outside_roots => 0".
According to the documentation:
The twig_roots mode builds only the required sub-trees from the docu-
ment Anything outside of the twig roots will just be ignored
and also:
twig_print_outside_roots
To be used in conjunction with the twig_roots argument. When
set to a true value this will print the document outside of
the
twig_roots elements.
So because you are setting twig_print_outside_roots to false it tells
XML::Twig to process only a part of your document. Try setting it to "1"...
----------------------------------
Offer Kaye
More information about the Perl
mailing list