
XML::SAX::Builder - build XML documents using SAX

my $x = XML::SAX::Builder->new;
$x->xml( $x->foo( 'bar' ) );
# Produces:
# <foo>bar</foo>
$x->xml( $x->foo( { id => 1 }, 'bar' ) );
# Produces:
# <foo id='1'>bar</foo>
$x->xml( $x->foo( $x->bar(1), 'middle', $x->baz ) );
# Produces:
# <foo><bar>1</bar>middle<baz /></foo>
$x->xml( $x->xmlns( '' => 'urn:foo', $x->foo( 'bar' ) ) );
# Produces:
# <foo xmlns='urn:foo'>bar</foo>
my $pfx = $x->xmlprefix( 'pfx' );
$x->xml( $x->xmlns( foo => 'urn:foo', $pfx->foo( 'bar' ) ) );
# Produces:
# <pfx:foo xmlns:pfx='urn:foo'>bar</pfx:foo>

This module is a set of classes to allow easy construction of XML documents, in particular in association with an XML::SAX pipeline. The default is to output the XML to stdout, although this is easily changed.

Return a new builder object. Optionall, a SAX HANDLER may be passed in. If none is passed in, the default is to use an XmL::SAX::Writer instead. The default configuration for XML::SAX::Writer sends XML to STDOUT. If you wish to get XML sent elsewhere, supply your own XML::SAX::Writer object.
Any element may be produced by calling it as a method on the Builder object. Each argument may be a previously created element, or a piece of text.
Optionally, the first argument may be a hash reference. If so, it will be used as a list of attributes for the element.
Calling this method actually creates the XML document. That is to say, it fires all the handlers for the objects that have been built up and passed in. No XML will be output until this method has been called.
This method inserts a new namespace into the resulting XML. PREFIX and URI are the namespace prefix and uri. CHILD is either an element object, or another namespace object.
Inserts all arguments concatenated together inside a <
CDATA doesn't work at present, because XML::Filter::BufferText, which is used by XML::SAX::Writer, gets it wrong (inheritance & AUTOLOAD - always a bad mix :).
Having to specify the top level element name to the doctype is nasty, but I can't see an obvious way to automatically pick it up right now.
You can't have a tag called DESTROY.

Alternative XML document constructors: XML::SAX::Generator, XML::Writer.

Dominic Mitchell, <cpan@semantico.com>

Copyright 2003 semantico
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.