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

Re: Using XML::Writer, how can I output to a file AND to the console?

by GrandFather (Cardinal)
on Dec 13, 2012 at 22:38 UTC ( #1008739=note: print w/ replies, xml ) Need Help??


in reply to Using XML::Writer, how can I output to a file AND to the console?

Open a file handle on a string:

use strict; use warnings; use XML::Writer; my $outputStr; open my $output, '>', \$outputStr; my $writer = new XML::Writer(OUTPUT => $output); $writer->startTag("greeting", "class" => "simple"); $writer->characters("Hello, world!"); $writer->endTag("greeting"); $writer->end(); close $output; print $outputStr;

Prints:

<greeting class="simple">Hello, world!</greeting>

Having captured the output to a string you can print where ever you want and as many times as you want.

Update helps to copy and paste the right stuff!

True laziness is hard work


Comment on Re: Using XML::Writer, how can I output to a file AND to the console?
Select or Download Code
Re^2: Using XML::Writer, how can I output to a file AND to the console?
by envinyater (Initiate) on Dec 14, 2012 at 14:37 UTC
    It works, Thank you :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-09-24 01:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (244 votes), past polls