Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Ouput XML::Writer to scalar

by jeffa (Bishop)
on May 02, 2003 at 14:05 UTC ( #254998=sourcecode: print w/replies, xml ) Need Help??
Category: Text Processing
Author/Contact Info /msg jeffa
Description: From time to time i have found myself wanting to capture the output from XML::Writer to a scalar instead of a file handle. It is simple enough, but i thought i would share here. Since XML::Writer expects an IO::Handle module for it's OUTPUT parameter, pass it an IO::Scalar. At the end, we can get a hold of that handle via XML::Writer::getOutput().
use strict;
use warnings;

use IO::Scalar;
use XML::Writer;

my $writer = XML::Writer->new(
    OUTPUT => IO::Scalar->new()

$writer->startTag("greeting", "class" => "simple");
$writer->characters("Hello, world!");

my $output = $writer->getOutput();

# optionally run $output through a filter

print $output;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2020-10-21 01:52 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (212 votes). Check out past polls.