Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML::Simple

0 views
Skip to first unread message

imthenachoman

unread,
May 10, 2008, 12:04:53 PM5/10/08
to
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'
}
]
}

xho...@gmail.com

unread,
May 11, 2008, 8:37:45 PM5/11/08
to
imthenachoman <imthen...@gmail.com> wrote:
> 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.

0 new messages