Perl - Read XML

Posted by chinna_82 on Stack Overflow See other posts from Stack Overflow or by chinna_82
Published on 2014-05-29T04:28:29Z Indexed on 2014/05/29 9:26 UTC
Read the original article Hit count: 332

Filed under:
|
|

XML

<?xml version='1.0'?>
<employee>
<name>Smith</name>
<age>43</age>
<sex>M</sex>
<department role='manager'>Operations</department>
</employee>

Perl

use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple;
foreach my $data1 ($data = $xml->XMLin("test.xml")) {
print Dumper($data1);
}

Above code managed to all the xml value like this.
Output

$VAR1 = {
          'department' => {
                            'content' => 'Operations',
                            'role' => 'manager'
                          },
          'name' => 'John Doe',
          'sex' => 'M',
          'age' => '43'
        };

How do I do, if I only want to get the role value. For this example I need to get Role => manager. Any advice or reference link is highly appreciated.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about perl