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

NAME

XML::Genx::Simple - A slightly simpler wrapper class for genx

SYNOPSIS

  use XML::Genx::Simple;
  my $w = XML::Genx::Simple->new;
  eval {
    # <root><foo id="1">bar</foo></root>
    $w->StartDocFile( *STDOUT );
    $w->StartElementLiteral( 'root' );
    $w->Element( foo => 'bar', id => 1 );
    $w->EndElement;
    $w->EndDocument;
  };
  die "Writing XML failed: $@" if $@;

DESCRIPTION

This class provides some helper methods to make using XML::Genx simpler in the common case.

METHODS

StartDocString ( )

Starts a new document, and collects the result into a string.

This method is offered as an extension to the genx API since it is significantly quicker. Many thanks to A. Pagaltzis for suggesting it.

GetDocString ( )

Returns the string from the current writer object.

NB: This is only guaranteed to be well-formed XML after you have called EndDocument().

NB: This will only produce sensible output if you've called StartDocString() previously.

Element ( NAME, TEXT, [ATTRS] )

Outputs <NAME>TEXT</NAME> in one go. NAME can be either a text string or an XML::Genx::Element object.

If NAME is a text string, an XML::Genx::Element object will be created, used and cached. So there's no real advantage to passing one in.

Optionally, ATTRS can be passed in as a list of key/value pairs. Again, each key used as an attribute name will be cached.

This method provides no namespace support.

SEE ALSO

XML::Genx.

AUTHOR

Dominic Mitchell, <cpan (at) happygiraffe.net>

The genx library was created by Tim Bray http://www.tbray.org/.

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Dominic Mitchell. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The genx library is:

Copyright (c) 2004 by Tim Bray and Sun Microsystems. For copying permission, see http://www.tbray.org/ongoing/genx/COPYING.

VERSION

@(#) $Id: Simple.pm 1270 2006-10-08 17:29:33Z dom $