in reply to Help!! XML::Simple with nested arrays
Try using Data::Dumper to examine the structure of $data. Then you might have better luck at figuring out how to access the various fields.
use Data::Dumper; print(Dumper($data));
You need
use strict ; use warnings ; use XML::Simple ; my $xml = <<'EOD' ; <database name="somedb"> <table name="table1"> <column name="column11" type="CHAR" /> <column name="column12" type="CHAR" /> </table> <table name="table2"> <column name="column21" type="CHAR" /> <column name="column22" type="CHAR" /> </table> </database> EOD my $data = XMLin( $xml, forcearray => 1 ) ; foreach my $table_name ( keys(%{$data->{'table'}}) ) { my $table = $data->{'table'}{$table_name}; foreach my $column_name ( keys(%{$table->{'column'}}) ) { my $column = $table->{'column'}{$column_name}; my $column_type = $column->{'type'}; print("Type of column $column_name in table $table_name is $colu +mn_type.\n"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help!! XML::Simple with nested arrays
by Frank John (Acolyte) on Jan 04, 2005 at 19:00 UTC | |
by ikegami (Patriarch) on Jan 04, 2005 at 19:26 UTC | |
by Frank John (Acolyte) on Jan 04, 2005 at 19:51 UTC | |
by ikegami (Patriarch) on Jan 04, 2005 at 20:02 UTC |