Tuesday, 29 December 2015

XML : how can I parse an XML tag that has an attribute, using perl

Below is a XML file,

     <?xml version='1.0'?>      <employee>        <name>Pradeep</name>        <age>23</age>        <sex>M</sex>        <department>Coder</department>      </employee>    

And the perl code is

   use XML::Simple;   use Data::Dumper;   @xml=new XML::Simple;   $data=@xml->XMLin("data.xml");   print Dumper($data);    

Now how do you parse if the XML file is

     <?xml version='1.0'?>        <employee="risc_31">         <name>John Doe</name>         <age>43</age>         <sex>M</sex>         <department>Analyst</department>        </employee>        <employee="risc_32">         <name>Pradeep</name>         <age>23</age>         <sex>M</sex>         <department>HR</department>        </employee>    

how can this be done using a foreach loop in perl

NOTE: XML::Simple is easier for me

Any help is appreciated!

No comments:

Post a Comment