Yak Shaving: XML::Writer edition

I am messing around trying to fix the QIF files that Lloyds TSB CC statements are presented as, and needed to write XML.

XML::Writer seems like a reasonable solution, but I’m not OK with writing a static header by using 300 calls to $writer->startTag(‘blah’).

This seems a good job for the computer; specifically for a SAX parser which will happily parse non-balanced XML. Anyway, the result is:

my $writer = XML::Writer::Lazy->new( OUTPUT => 'self');
my $title  = "My Title!";

        <p>Pipe in literal XML</p>

$writer->startTag( "p", "class" => "simple" );
$writer->characters("Alongside the usual interface");


Which is considerably lazier, and allows you to intersperse actual XML::Writer commands with chunks of XML string and have it do largely the right thing.

Leave a comment

About Peter Sergeant

user-pic I blog about Perl.