in reply to XML::Parser - Obtaining Attributes
However, despite playing around with this for ages, I cannot seem toI once felt the same way about XML::Parser, which is why I switched to XML::Twig:
use warnings; use strict; use XML::Twig qw(); use Data::Dumper qw(Dumper); $Data::Dumper::Sortkeys = 1; my $xml = <<XML; <products> <product> <description>Product description.</description> <image>some url</image> <categories> <category catname="Books" id="xyz" name="Books"/> </categories> <prodname>Product name</prodname> </product> </products> XML my $twig = XML::Twig->new( twig_handlers => { category => \&category }, ); $twig->parse($xml); sub category { my ($t, $cat) = @_; print Dumper($cat->atts()); } __END__ $VAR1 = { 'catname' => 'Books', 'id' => 'xyz', 'name' => 'Books' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Parser - Obtaining Attributes
by DanielSpaniel (Scribe) on Jan 25, 2014 at 00:36 UTC |