MKDoc::XML::Dumper(3) Same as Data::Dumper, but with XML


use MKDoc::XML::Dumper;
use Test::More 'no_plan';

my $stuff = [ qw /foo bar baz/, [], { hello => 'world', yo => \\'boo' } ];
my $xml = MKDoc::XML::Dumper->perl2xml ($stuff);
my $stuff2 = MKDoc::XML::Dumper->xml2perl ($xml);
is_deeply ($stuff, $stuff2); # prints 'ok'


MKDoc::XML::Dumper provides functionality equivalent to Data::Dumper except that rather than serializing structures into a Perl string, it serializes them into a generic XML file format.

Of course since XML cannot be evaled, it also provides a mechanism for undumping the xml back into a perl structure.

MKDoc::XML::Dumper supports scalar references, hash references, array references, reference references, and litterals. It also supports circular structures and back references to avoid creating unwanted extra copies of the same object.

That's all there is to it!


my $xml = MKDoc::XML::Dumper->perl2xml ($perl);

Turns $perl into an XML string. For instance:

  my $perl = [ qw /foo bar baz/, { adam => 'apple', bruno => 'berry', chris => 'cherry' } ];
  print MKDoc::XML::Dumper->perl2xml ($perl);'

Will print something like:

  <array id="135338912">
    <item key="0">
    <item key="1">
    <item key="2">
    <item key="3">
      <hash id="135338708">
        <item key="bruno">
        <item key="adam">
        <item key="chris">

As you can see, every object has an id. This allows for backreferencing, so:

  my $perl = undef;
  $perl    = \$perl;
  print MKDoc::XML::Dumper->perl2xml ($perl);'

Prints something like:

  <ref id="135338888">
    <backref id="135338888" />

For the curious, these identifiers are computed using some perl black magic:

  my $id = 0 + $reference;

my $perl = MKDoc::XML::Dumper->perl2xml ($xml);

Does the exact reverse operation as xml2perl().


Copyright 2003 - MKDoc Holdings Ltd.

Author: Jean-Michel Hiver

This module is free software and is distributed under the same license as Perl itself. Use it at your own risk.