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.

Learning without thought is labor lost; thought without learning is perilous. - Confucius
WebChalkboard.com | For the love of art...

In reply to Parsing XML Simple Output by webchalkboard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.