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().
my $writer = XML::Writer->new(
OUTPUT => IO::Scalar->new()
$writer->startTag("greeting", "class" => "simple");
my $output = $writer->getOutput();
# optionally run $output through a filter