in reply to searching the XML file for certain nodes
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: searching the XML file for certain nodes
by mirod (Canon) on Mar 10, 2009 at 15:45 UTC | |
by Jenda (Abbot) on Mar 10, 2009 at 23:08 UTC | |
by Anonymous Monk on Mar 13, 2009 at 10:57 UTC |