2010/5/11 Parag Kalra <paragka...@gmail.com>:
> Hey All,
>
> I am trying to design some scripts using the module - XML::Parser
>
> To start  learning I have a very basic scenario. Suppose I have following
> XML file:
>
> <root>
> <tag1>My Tag1</tag1>
> <tag2>My Tag2</tag2>
> <tag3>My Tag3</tag3>
> </root>
>
> I want to save the the tags as the keys of a Hash and respective content as
> the  value of that hash
>
> So for the above XML file using the module XML::Parser, I would like to
> create a hash having following key/value pair:
>
> my %my_hash = (
>        tag1 => 'My Tag1',
>        tag2 => 'My Tag2',
>        tag3 => 'My Tag3',
>    );
>
> Is that possible?
>

Sure it's possible.

$ cat xml.pl
use strict;
use XML::Simple;
use Data::Dumper;

my $xml=<<EOF;
<root>
<tag1>My Tag1</tag1>
<tag2>My Tag2</tag2>
<tag3>My Tag3</tag3>
</root>
EOF

my $re = XMLin($xml);
print Dumper $re;


$ perl xml.pl
$VAR1 = {
          'tag3' => 'My Tag3',
          'tag1' => 'My Tag1',
          'tag2' => 'My Tag2'
        };


-- 
Tech support agency in China
http://duxieweb.com/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to