I am trying to extract xml data with the xml::parser module and to store them into an array of hashes for further processing - tag extraction works fine, but storing the tag values into the array of hashes is the issue.
May be you can assist me here and what I am doing wrong:
xml data file:
<Catalog> <Category> <Name>Arts & Entertainment</Name> <Site> <Id>...</Id> <Title>...</Title> </Site> <Site> <Id>...</Id> <Title>...</Title> </Site> </Category> <Catalog>
perl prg:
Thanks for assistance, Peter$parser = XML::Parser->new(Handlers => {Start => \&start, Char => \&char, End => \&end} ); sub start{ my ($p, $elt, %atts) = @_; if ($elt eq 'Site') { %site = (); #this is the hash per one site } if ($elt eq 'Id') { $tag_id = 1; } if ($elt eq 'Title') { $tag_title = 1; } } sub char { my ($p, $str) = @_; if ($tag_id eq 1) { $id = trim($str); } if ($tag_title eq 1) { $title = trim($str); } } sub end{ my ($p, $elt) = @_; if ($tag_id eq 1 and $elt eq 'Id') { $site{ $id } = $id; $tag_id = 0; } if ($tag_title eq 1 and $elt eq 'Title') { $site{ $title } = $title; $tag_title = 0; } if ($elt eq 'Site') { push(@cb, %site); print %site . "\n"; } } # if I want to process now the @cb then no data are inside.
In reply to parse xml and store data in array of hashesh by osprofi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |