XML::Simple

I

imthenachoman

I am having some problems with XML::Simple and forcearray. I am trying
to get the XML file read in as an array instead of into a hash. I am
on Perl 5.6.1 and XML::Simple 1.06 and I can not updated. I have to
figure out how to do this on the system I am on.

####################################################################################
XML File:
<?xml version='1.0'?>
<apps>
<app name="a" id="a">
</app>
<app name="b" id="b">
</app>
</apps>

####################################################################################
Perl Script:
my $xml = new XML::Simple();
my $data = $xml->XMLin(undef, forcearray => ['blah', 'apps','app',
'name', 'id'] );

print( Dumper($data) );

####################################################################################
Output:
$VAR1 = {
'app' => {
'a' => {
'id' => 'a'
},
'b' => {
'id' => 'b'
}
}
}

####################################################################################
Desired Output:
$VAR1 = {
'app' => [
{
name => 'a',
id => 'a'
},
{
name => 'b',
id => 'b'
}
]
}
 
X

xhoster

imthenachoman said:
I am having some problems with XML::Simple and forcearray. I am trying
to get the XML file read in as an array instead of into a hash. I am
on Perl 5.6.1 and XML::Simple 1.06 and I can not updated. I have to
figure out how to do this on the system I am on.

#########################################################################
########### XML File:
<?xml version='1.0'?>
<apps>
<app name="a" id="a">
</app>
<app name="b" id="b">
</app>
</apps>

#########################################################################
########### Perl Script:
my $xml = new XML::Simple();
my $data = $xml->XMLin(undef, forcearray => ['blah', 'apps','app',
'name', 'id'] );

You need to change KeyAttr from its default, e.g. KeyAttr => [],

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top