Perl snippet:
my $xml = new XML::Simple(
KeyAttr=>{
property => 'propertyname',
},
ForceArray => 1,
ContentKey => '-content');
my $config = $xml->XMLin($configFile);
Configfile looks like:
<config>
<property propertyname="text1" b="text2" c="text3" d="text4">
text5
</property>
<property propertyname="text6" b="text7" c="text8" d="text9">
text10
</property>
</config>
How do I parse this config file so that c becomes a key and I can access the corresponding b and d? What does KeyAttr do?
XML::Simplereturns a Perl data structure (see perldoc perldsc) which you can visualize using Data::Dumper.Here is one way to access the data you need:
Output:
You can read about
KeyAttrfrom perldoc XML::Simple