Apart from XML::Twig you could also use XML::Rules like this:
Unlike some of the suggested XML::Twig solutions this doesn't kep the whole document in memory, at each moment at most the data from a single <AI> tag and the attributes of the unclosed parent tags are kept.use XML::Rules; my $AC_n = 'CCC'; my $parser = XML::Rules->new( rules => [ _default => 'as is', # by default keep both attributes and _content 'Desc,What,AR' => 'content', # for those keep just the content '^AC' => sub {return ($_[1]->{n} eq $AC_n)}, # only process the <AC> tags whose n attribute equals the $AC_n AC => '', # once processed, forget the contents of the <AC> tag AI => sub {print "Found AI: n=$_[1]->{n}, desc=$_[1]->{Desc}\n"; r +eturn}, # for each processed AI tag print the n attribute and Desc subtag +. # thanks to the 2nd rule you don't have to write # $_[1]->{Desc}{_contents} # As this rule returns nothing, the contents of the tag are not r +emembered. ], ); $parser->parse($XML);
In reply to Re: XML::Twig question
by Jenda
in thread XML::Twig question
by thandi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |