XML, the Perl Way

Processing XML with Perl Michel Rodriguez

XML::Dumper

Other Modules

XML::Dumper (cont'd)

Examples

Convert a Perl data structure to XML:

 use XML::Dumper;
 my $dump = new XML::Dumper;
 $data = [ { first => 'Jonathan', last => 'Eisenzopf', email => 'eisen@pobox.com' },
           { first => 'Larry', last => 'Wall', email => 'larry@wall.org' }
         ];
 $xml =  $dump->pl2xml($data);
 print $xml;

Reload the data from the XML ffile:

 use XML::Dumper;
 my $dump = new XML::Dumper; 
 my $data = $dump->xml2pl($Tree);

The XML produced is:

<perldata>
 <array>
  <item key="0">
   <hash>
    <item key="last">Eisenzopf</item>
    <item key="first">Jonathan</item>
    <item key="email">eisen@pobox.com</item>
   </hash>
  </item>
  <item key="1">
   <hash>
    <item key="last">Wall</item>
    <item key="first">Larry</item>
    <item key="email">larry@wall.org</item>
   </hash>
  </item>
 </array>
</perldata>      


XML::Dumper

Other Modules