Google Groups Home
Help | Sign in
Message from discussion XML::Simple
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
imthenachoman  
View profile
 More options May 10, 12:04 pm
Newsgroups: comp.lang.perl.misc
From: imthenachoman <imthenacho...@gmail.com>
Date: Sat, 10 May 2008 09:04:53 -0700 (PDT)
Local: Sat, May 10 2008 12:04 pm
Subject: XML::Simple
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'
                     }
                   ]
        }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google