XML::Simple - how to iterate through records?
by Phil Brodd other posts by this author
Jul 10 2001 9:14PM messages near this date
view in the new Beta List Site
RE: PerlSax to parse/search large (~350 MB) file
|
RE: :Simple - how to iterate through records?
I've been playing with XML::Simple, which seems quite nice. What I don't
understand is how to refer to the entire array that is the value of the
'request' key below, or how to iterate through its elements.
I am able to reference individual elements of the array with
$hashref-> {request}->[index], but how do I refer to the whole thing?
Thanks.
Phil Brodd
$VAR1 = {
'request' => [
{
'section' => [
'003'
],
'department' => [
'22C'
],
'webct_id' => [
'jblah'
],
'year' => [
'2002'
],
'course' => [
'017'
],
'repeating' => 'no',
'termination_date' => '15-9-2002',
'error_count' => '0',
'session' => [
'3'
],
'email' => [
'joan-blah@the.edu'
]
},
.
.
.
]
};
use XML::Simple;
my $xs = new XML::Simple(forcearray => 1,
rootname => "autoreg",
xmldecl => 1
);
my $hashref = $xs-> XMLin('autoreg.xml');
## create a hash reference with the request data
my $request = {
# attributes
'repeating' => 'yes',
'termination_date' => '15-9-2002',
'error_count' => '0',
# child elements
'department' => ['009'],
'user_id' => ['jjack'],
'year' => ['2002'],
'course' => ['100'],
'section' => ['001'],
'session' => ['3'],
'email' => ['joe-jack@the.edu']
};
$hashref-> {request}->[2] = $request;
my $xml = $xs-> XMLout($hashref);
Here is my XML:
<?xml version='1' standalone='yes'?>
<autoreg>
<request repeating="no" termination_date="15-9-2002" error_count="0">
<section> 003</section>
<department> 22c</department>
<user_id> jblah</user_id>
<year> 2002</year>
<course> 017</course>
<session> 3</session>
<email> joan-blah@[...].edu</email>
</request>
<request repeating="yes" termination_date="15-9-2002" error_count="0">
<section> 009</section>
<department> 08g</department>
<user_id> lyadda</user_id>
<year> 2002</year>
<course> 017</course>
<session> 3</session>
<email> larry-yadda@[...].edu</email>
</request>
</autoreg>
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
http://listserv.ActiveState.com/mailman/listinfo/perl-xml
Thread:
Phil Brodd
Sterin, Ilya
|