Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Missing values in XML::Twig Output

by mirod (Canon)
on May 03, 2011 at 16:00 UTC ( [id://902744]=note: print w/replies, xml ) Need Help??


in reply to Missing values in XML::Twig Output

When you use the twig_print_outside_roots option, the XML outside of the roots is output as soon as it is parsed. So you need to output the changed tags as soon as they are parsed too, ie in the handler, not after the end of the parse.

So you code should look like this:

open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' f +or writing: $!"; my $t = XML::Twig->new( twig_roots => {'display-name' => sub { convert( @_, +$fh_out) } }, twig_print_outside_roots => $fh_out, # as mentioned in a previous +response pretty_print => 'nice' ); # including data for ease of post $t->parsefile( $file); sub convert { my ($t, $elt, $fh) = @_; ... # do what you have to do to $elt $elt->print( $fh); # this is where you have to print it }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://902744]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-19 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found