Monday, August 28, 2006

Linux:: Perl and XML

I am learning Perl and its ability with XML,. Because the structure of my domcument is not too hard, I use:

use XML::Simple;
What I want is to generate an xml output. But it means I need to undestand how to create a Perl structure which can be translate in the XML I want... To do that, I make "reverse engineering" by using this simple script:


#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

my $xs = new XML::Simple(keeproot => 1,searchpath => ".",
forcearray => 1, keyattr => [key, tag]);
my $ref = $xs->XMLin("point.xml");
my $xml = $xs->XMLout($ref);
print "\nHash dump with 'keyattr => [key, tag]':\n";
print Dumper($ref);

print "\nXML output with 'keyattr => [key, tag]':\n";
print $xml;
exit;

No comments: