NAME

Data::Dump::XML - Dump arbitrary data structures as XML::LibXML object

SYNOPSIS

 use Data::Dump::XML;
 my $dumper = Data::Dump::XML->new;
 $xml = $dumper->dump_xml (@list);

PROJECT

Project source code and repository available on http://sourceforge.net/projects/web-app.

DESCRIPTION

This module completely rewritten from Gisle Aas Data::DumpXML to manage perl structures in XML using interface to gnome libxml2 (package XML::LibXML). Module provides a single method called dump_xml that takes a list of Perl values as its argument. Returned is an XML::LibXML::Document object that represents any Perl data structures passed to the function. Reference loops are handled correctly.

Compatibility with Data::DumpXML is absent.

As an example of the XML documents produced, the following call:

  $a = bless {a => 1, b => {c => [1,2]}}, "Foo";
  $dumper->dump_xml($a)->toString (1);

produces:

  <?xml version="1.0" encoding="utf-8"?>
  <data _class="Foo">
        <a>1</a>
        <b>
                <c>
                        <item>1</item>
                        <item>2</item>
                </c>
        </b>
  </data>

Comparing to Data::DumpXML this module generates noticeably more simple XML tree, based on assumption that links in perl can be defined in implicit way, i.e.: explicit: $a->{b}->{c}->[1]; implicit: $a->{b} {c} [1];

And make possible similar xpath expressions: /data/b/c/*[count (preceding-sibling) = 1]

Data::Dump::XML::Parser is a class that can restore data structures dumped by dump_xml().

Configuration variables

The generated XML is influenced by a set of configuration variables. If you modify them, then it is a good idea to localize the effect. For example:

        my $dumper = new Data::Dump::XML {
                # xml configuration
                'encoding'            => 'utf-8',
                'dtd-location'        => '',
                'namespace'           => {},

                # xml tree namespace
                'dump-config'         => 1,
                'root-name'           => 'data',
                'hash-element'        => 'key',
                'array-element'       => 'item',
                'ref-element'         => 'ref',
                'empty-array'         => 'empty-array',
                'empty-hash'          => 'empty-hash',
                'undef'               => 'undef',
                'key-as-hash-element' => 1,
                '@key-as-attribute'   => 1,

                # options
                'sort-keys'           => 0,
                'granted-restore'     => 1,
        }

Data::DumpXML is function-oriented, but this module is rewritten to be object-oriented, thus configuration parameters are passed as hash into constructor.

The variables are:

encoding

Encoding of produced document. Default - 'utf-8'.

dtd-location

This variable contains the location of the DTD. If this variable is non-empty, then a <!DOCTYPE ...> is included in the output. The default is "". Usable with key-as-hash-element parameter.

namespace

This hash contains the namespace used for the XML elements. Default: disabled use of namespaces.

Namespaces provides as full attribute name and location. Example:

        ...
        'namespace' => {
                'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform',
                'xmlns:xi'  => 'http://www.w3.org/2001/XInclude',
        }
        ...
root-name

This parameter define name for xml root element.

hash-element, array-element ref-element

This parameters provides names for hash, array items and references.

Defaults:

        ...
        'hash-element'  => 'key',
        'array-element' => 'item',
        'ref-element'   => 'ref',
        ...
key-as-hash-element

When this parameter is set, then each hash key, correspondending regexp /^(?:[^\d\W]|:)[\w:-]*$/ dumped as:

        <$keyname>$keyvalue</$keyname>

        instead of 

        <$hashelement name="$keyname">$keyvalue</$hashelement>
@key-as-attribute

TODO

granted_restore

TODO

XML::LibXML Features

When dumping XML::LibXML::Element objects, it added by childs to current place in document tree.

BUGS

The content of globs and subroutines are not dumped. They are restored as the strings "** glob **" and "** code **".

LVALUE and IO objects are not dumped at all. They simply disappear from the restored data structure.

SEE ALSO

Data::DumpXML, XML::Parser, XML::Dumper, Data::Dump, XML::Dump

AUTHORS

The Data::Dump::XML module is written by Ivan Baktsheev <dot.and.thing@gmail.com>, based on Data::DumpXML.

The Data::Dump module was written by Gisle Aas, based on Data::Dumper by Gurusamy Sarathy <gsar@umich.edu>.

        Copyright 2003-2009 Ivan Baktcheev.
        Copyright 1998-2003 Gisle Aas.
        Copyright 1996-1998 Gurusamy Sarathy.

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

http://perlhug.com