The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::Writer::Simpler - Perl extension for writing XML data

SYNOPSIS

DESCRIPTION

This is a convenience module for writing XML. It's a subclass of XML::Writer, with a single convenience method so you usually won't have to deal with remembering to call startTag(), endTag(), and emptyTag().

This module is lies somewhere in between XML::Generator and XML::Writer::Nest. It nests calls like XML::Generator, but allows for arbitrary subroutine calls as well. It requires fewer braces in general than XML::Writer::Nest.

This module is a subclass of XML::Writer, so if you can't do what you want to with the tag method, you can fall back to the methods native to XML::Writer.

METHODS

  • new

        XML::Writer::Simpler->new(%params);

    Creates the object. Acceptable hash keys for %params are the same as those for XML::Writer. This module assumes everything is UTF-8, so you can omit that if you like; it will be provided for you.

  • tag

        $xml->tag($tagName, [ \@attributes ], $content);

    If $content is a plain scalar value, will output the tag with that content. If no content is provided, will output an empty tag:

        $xml->tag('example', 'foo');    # <example>foo</example>
        $xml->tag('example');           # <example />

    You may also pass an array ref of key/value pairs that wind up as attributes:

        # <example bar="baz">foo</example>
        $xml->tag('example', [bar => 'baz'], 'foo');
    
        # <example bar="baz" />
        $xml->tag('example', [bar => 'baz']);

    If $content is a code ref, this will start the tag, execute the code ref, then close the tag. This allows arbitrarily deep/complex tag structures.

        # <example1><exA>Text 1</exA><exB>Text 2</exB></example1>
        $xml->tag('example1', sub {
            $xml->tag('exA', 'Text 1');
            $xml->tag('exB', 'Text 2');
        });
    
        # <example2><a>100</a><b>101</b><c>102</c></example2>
        $xml->('example2', sub {
            for (my $tag = 'a', my $num = 100; $num < 103; $tag++, $num++) {
                $xml->($tag, $num);
            }
        });

    These different styles of calling can be combined in a number of ways to output basically whatever you like.

        # <example3 id='ex3'>text z</example3>
        $xml->tag('example3', [id => 'ex3'], 'text z');
    
        # <example4 id="ex4"><exZ>more text</exZ></example4>
        $xml->tag('example4', [id => 'ex4'], sub {
            $xml->tag('exZ', 'more text');
        });

SEE ALSO

XML::Writer

AUTHOR

Michael McClimon, <michael at mcclimon.org>

BUGS

Please report any bugs or feature requests to bug-xml-writer-simple at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Writer-Simpler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. See also the Github repository at http://github.com/mmcclimon/XML-Writer-Simpler.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc XML::Writer::Simpler

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2013 Michael McClimon.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.