Hey Monks
Was wondering if anyone could help me work out how to parse the output I have got from loading my XML file into XML::Simple.
Here is my program so far...
use XML::Simple; my $filename="file.xml"; my $xml = XMLin($filename); ## produces the output below print Dumper($xml); ## this bit isn't right because the xml isnt in ## an array but I dont know how to reference ## the products and put them into an array my @products = @{$xml->{product}}; foreach my $item (@products) { Print "Department: $item->{department}\n"; Print "Manufacturer: $item->{manufacturer}\n"; }
How can I loop through each of the products and get the values for each of the elements? I need to insert these into a database...
This is the structure of my XML file, as output by Dumper.
$VAR1 = { 'product' => { 'ORANGE MOTO V545' => { 'department' => 'Computing & Phones', 'startdate' => '1900-01-01 00:00:00.0', 'format' => {}, 'manufacturer' => 'ORANGE' }, 'MORPHY RICHARDS 44411' => { 'department' => 'Kitchen & Home', 'startdate' => '1900-01-01 00:00:00.0', 'format' => {}, 'manufacturer' => 'MORPHY RICHARDS' }, };
Thanks so much.
In reply to Parsing XML Simple Output by webchalkboard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |