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' };
In reply to Re: XML::Parser - Obtaining Attributes
by toolic
in thread XML::Parser - Obtaining Attributes
by DanielSpaniel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |