Data::DumpXML - Dump arbitrary data structures as XML |
Data::DumpXML - Dump arbitrary data structures as XML
use Data::DumpXML qw(dump_xml); $xml = dump_xml(@list)
This module provides a single function called dump_xml()
that takes a
list of Perl values as its argument and produces a string as its result.
The string returned is an XML document that represents any Perl data
structures passed to the function. Reference loops are handled correctly.
The following data model is used:
data : scalar* scalar = undef | str | ref | alias ref : scalar | array | hash | glob | code array: scalar* hash: (key scalar)*
The distribution comes with an XML schema and a DTD that more formally describe this structure.
As an example of the XML documents produced, the following call:
$a = bless [1,2], "Foo"; dump_xml($a);
produces:
<?xml version="1.0" encoding="US-ASCII"?> <data xmlns="http://www.cpan.org/.../Data-DumpXML.xsd"> <ref> <array class="Foo"> <str>1</str> <str>2</str> </array> </ref> </data>
If dump_xml()
is called in a void context, then the dump is printed
on STDERR automatically. For compatibility with Data::Dump
, there
is also an alias for dump_xml()
called simply dump().
Data::DumpXML::Parser
is a class that can restore
data structures dumped by dump_xml().
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:
sub my_dump_xml { local $Data::DumpXML::INDENT = ""; local $Data::DumpXML::XML_DECL = 0; local $Data::DumpXML::DTD_LOCATION = ""; local $Data::DumpXML::NS_PREFIX = "dumpxml";
return dump_xml(@_); }
The variables are:
xsi:schemaLocation
attribute is
added to the top level data
element. The default is not to include
this, as the location can be inferred from the default XML namespace
used.
Class names with 8-bit characters are dumped as Latin-1, but converted to UTF-8 when restored by the Data::DumpXML::Parser.
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.
the Data::DumpXML::Parser manpage, the XML::Parser manpage, the XML::Dumper manpage, the Data::Dump manpage
The Data::DumpXML
module is written by Gisle Aas <gisle@aas.no>,
based on Data::Dump
.
The Data::Dump
module was written by Gisle Aas, based on
Data::Dumper
by Gurusamy Sarathy <gsar@umich.edu>.
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.
Data::DumpXML - Dump arbitrary data structures as XML |