#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use XML::Simple;
my $gXML;
my $gXMLDoc;
my $gXMLString;
$/ = undef;
$gXMLString = <DATA>;
$gXML = XML::Simple->new();
$gXMLDoc = $gXML->XMLin($gXMLString);
print 'Before:',"\n",'-' x 40,"\n",Dumper($gXMLDoc),"\n";
$gXMLDoc = $gXML->XMLin($gXMLString, keyattr => '');
print 'After:',"\n",'-' x 40,"\n",Dumper($gXMLDoc),"\n";
__DATA__
<DataContent>
<head>
<meta name="APU:IndustryCode" content="Banking / finance" />
<meta name="APU:IndustryCode" content="Joint ventures / investment" />
</head>
</DataContent>
For more information on the options available with XML::Simple (forcearray is another one you will want to make sure you know), check out: perldoc XML::Simple
Note:
Make sure you look at the data structure dumped with Data::Dumper -- meta is now a two element array.
Update:
The following code will iterate through the meta array:
foreach (0..$#{$gXMLDoc->{head}->{meta}})
{
print $gXMLDoc->{head}->{meta}[$_]->{content},"\n";
}
|