use strict; use warnings; use XML::Twig; my $xmlStr = <<XML; <foo> <qp> <q supp="yes">hello</q> <q supp="no">bye</q> <xr supp="yes">later</xr> </qp> </foo> XML my $twig= XML::Twig->new(); $twig->parse($xmlStr); my $elt = $twig->root(); my @qps = $elt->children('qp'); my $numOfQuotes = 0; for my $qp (@qps) { for my $q ($qp->children( qr/^(q|xr)$/ )) { $numOfQuotes++ if $q->att('supp') eq 'yes'; } } print "numOfQuotes = $numOfQuotes\n"; __END__ numOfQuotes = 2
In reply to Re: XML::twig counting elements that don't have a certain attribute/value on them
by toolic
in thread XML::twig counting elements that don't have a certain attribute/value on them
by mertserger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |