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

NAME

Data::DumpXML - Dump arbitrary data structures as XML

SYNOPSIS

 use Data::DumpXML qw(dump_xml);
 $xml = dump_xml(@list)

DESCRIPTION

This module provide a single function called dump_xml() that takes a list of something as argument and produce a string as result.

The string returned is an XML document that represents any perl data structure passed in. The following DTD is used:

  <!DOCTYPE data [
   <!ENTITY % listtype "undef | str | ref | alias">

   <!ELEMENT data (%listtype;)*>
   <!ELEMENT undef EMPTY>
   <!ELEMENT str (#PCDATA)>
   <!ELEMENT ref (%listtype; | array | hash | glob | code)>
   <!ELEMENT alias EMPTY>
   <!ELEMENT array (%listtype;)*>
   <!ELEMENT hash  (key, (%listtype;))*>
   <!ELEMENT key (#PCDATA)>
   <!ELEMENT glob EMPTY>
   <!ELEMENT code EMPTY>

   <!ENTITY % stdattlist 'id       ID             #IMPLIED
                          class    CDATA          #IMPLIED'>
   <!ENTITY % encoding   'encoding (plain|base64) "plain"'>

   <!ATTLIST undef %stdattlist;>
   <!ATTLIST ref %stdattlist;>
   <!ATTLIST undef %stdattlist;>
   <!ATTLIST array %stdattlist;>
   <!ATTLIST hash %stdattlist;>
   <!ATTLIST glob %stdattlist;>
   <!ATTLIST code %stdattlist;>

   <!ATTLIST str %stdattlist; %encoding;>
   <!ATTLIST key %encoding;>

   <!ATTLIST alias ref IDREF #IMPLIED>
  ]>

As an example of the XML documents producted; the following call:

  $a = bless [1,2], "Foo";
  $a->[2] = \$a;
  $b = $a;
  dump_xml($a, $b);

will produce:

  <?xml version="1.0" encoding="US-ASCII"?>
  <data>
   <ref id="r1">
    <array class="Foo" id="r2">
     <str>1</str>
     <str>2</str>
     <ref>
      <alias ref="r1"/></ref></array></ref>
   <ref>
    <alias ref="r2"/></ref></data>

If dump_xml() is called in void context, then the dump will be printed on STDERR instead of being returned. For compatibility with Data::Dump there is also an alias for dump_xml() simply called dump().

You can set the variable $Data::DumpXML::INDENT to control indenting before calling dump_xml(). To suppress indenting set it as "".

The Data::DumpXML::Parser is a class that can restore datastructures dumped by dump_xml().

BUGS

Class names with 8-bit characters will be 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 will simply disappear from the restored data structure.

SEE ALSO

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

AUTHORS

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-2000 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.