use strict; use XML::Rules; my $filter = XML::Rules->new( style => 'filter', rules => { _default => 'raw', p => sub { my ($tag, $attr) = @_; if ($attr->{v} eq 'YES') { return $tag => $attr } else { return; } }, }, ); $filter->filter(\*DATA); __DATA__ <?xml version="1.0" encoding="UTF-8" ?> <e> <p id="1" v="YES"> <e1>The</e1> <e2>Bye</e2> </p> <p id="2" v="NO"> <e1>Border</e1> <e2>Lamp</e2> </p> </e>
Unlike the XML::LibXML and the presented XML::Twig solutions, this one doesn't keep the whole (original or resulting) document in memory, instead it only stores the contents of one <p> at any time. If the file is huge and contains a lot of small <p> tags, this may make a big difference.
In reply to Re: searching the XML file for certain nodes
by Jenda
in thread searching the XML file for certain nodes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |