Data::Dump::XML - Dump arbitrary data structures as XML::LibXML object
use Data::Dump::XML; my $dumper = Data::Dump::XML->new; $xml = $dumper->dump_xml (@list);
Project source code and repository available on http://sourceforge.net/projects/web-app.
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.
Data::DumpXML
XML::LibXML::Document
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().
Data::Dump::XML::Parser
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 of produced document. Default - 'utf-8'.
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.
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', } ...
This parameter define name for xml root element.
This parameters provides names for hash, array items and references.
Defaults:
... 'hash-element' => 'key', 'array-element' => 'item', 'ref-element' => 'ref', ...
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>
TODO
When dumping XML::LibXML::Element objects, it added by childs to current place in document tree.
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.
Data::DumpXML, XML::Parser, XML::Dumper, Data::Dump, XML::Dump
The Data::Dump::XML module is written by Ivan Baktsheev <dot.and.thing@gmail.com>, based on Data::DumpXML.
Data::Dump::XML
The Data::Dump module was written by Gisle Aas, based on Data::Dumper by Gurusamy Sarathy <gsar@umich.edu>.
Data::Dump
Data::Dumper
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
To install Data::Dump::XML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Dump::XML
CPAN shell
perl -MCPAN -e shell install Data::Dump::XML
For more information on module installation, please visit the detailed CPAN module installation guide.