Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: XML::Twig outputting root element start tag twice

by benizi (Hermit)
on Apr 25, 2006 at 15:20 UTC ( [id://545578]=note: print w/replies, xml ) Need Help??


in reply to Re^2: XML::Twig outputting root element start tag twice
in thread XML::Twig outputting root element start tag twice

Hey, sorry for the slow response. I left for a vacation shortly after I posted my question. The filehandle is not in scope because the handlers are defined in a module and passed to the twig like this: (paraphrased)

... use Handlers::Library qw/:handlers/; ... open my $filehandle, '>', 'output.xml' or die ">output.xml:$!"; my $p = XML::Twig->new( twig_handlers => { foo => \&foo_handler }, );

I'm going to end up doing what I was trying to avoid in the first place: passing a filehandle to all of the ->flush calls. When I asked the original question, I figured this was something XML::Twig would naturally support. (It's wonderfully DWIMmy, and does something similar for defaulting a filehandle with twig_print_outside_roots => $filehandle, but I didn't realize that that was just a select.)

So, long story short, my final code will be something like: (untested)

package Handlers::Library; my $twig_fh; BEGIN { $twig_fh = *STDOUT; } sub twig_output { my $name = shift; open $twig_fh, '>', $name or die ">$name: $!"; } sub foo_handler { ... $twig->flush($twig_fh) } sub bar_handler { ... $twig->flush($twig_fh) }
use Handlers::Library qw/:handlers/; twig_output('output.xml'); my $p = XML::Twig->new(...);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found