NAME

XML::Struct::Writer - Process ordered XML as stream, for instance to write XML

VERSION

version 0.02

SYNOPSIS

use XML::Struct::Writer;

my $writer = XML::Struct::Writer->new;
my $xml = $writer->writeDocument( [
    greet => { }, [
        "Hello, ",
        [ emph => { color => "blue" } , [ "World" ] ],
        "!"
    ]
] ); 

$xml->toFile("greet.xml");

DESCRIPTION

This module transforms an XML document, given in form of a data structure as described in XML::Struct, into a stream of SAX1 events. By default, the stream is used to build a XML::LibXML::Document that can be used for instance to write the XML document to a file.

METHODS

writeDocument( $root )

writeElement( $element )

WRITING TO HANDLERS

The handler property can be used to specify a SAX handler that XML stream events are send to. By default XML::LibXML::SAX::Builder is used to build a DOM that is serialized afterwards. Using another handler should be more performant for serialization. See XML::Writer, XML::Handler::YAWriter (and possibly XML::SAX::Writer combined with XML::Filter::SAX1toSAX2) for stream-based XML writers.

Handlers do not need to support all features of SAX. A handler is expected to implement the following methods:

  • start_document()
  • start_element( { Name => $name, Attributes => \%attributes } )
  • end_element( { Name => $name } )
  • characters( { Data => $characters } )
  • end_document()

If the handler further implements a result() method, it is called at the end of writeDocument.

AUTHOR

Jakob Voß

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Jakob Voß.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 151:

Non-ASCII character seen before =encoding in 'Voß'. Assuming UTF-8