Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Ouput XML::Writer to scalar

by jeffa (Bishop)
on May 02, 2003 at 14:05 UTC ( [id://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!");
$writer->endTag("greeting");
$writer->end();

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

# optionally run $output through a filter

print $output;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-18 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found