in reply to XML::Parser - Obtaining Attributes

However, despite playing around with this for ages, I cannot seem to
I 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

    Thanks for the suggestion. Appreciated.

    I'd prefer to make it work with XML::Parser if I can, but I'll certainly try your suggestion if I can't make any progress.

    Just curious, never having used twig, does one need to define a twig_handler for every tag one wishes to process? ... i.e. I need a bunch of information from most, but not all, elements, as well as the category attributes.

    Thx!