in reply to XML::Twig - How do I check to see if an element exists in root?
something like this would work:
should be reasonably fast, too. For a possibly simpler (and probably slower) approach, you might want to look at the "descendants" method in XML::Twig.use strict; use XML::Twig; my @nodes = qw(title toc bar); my %found; my $t = XML::Twig->new( twig_handlers => { map { $_ => sub { $found{$_->name()}++ }; } @no +des } ); $t->parsefile(shift()); # read file specified at command line $t->flush; # update: you may need this for (@nodes) { die "$_ not found" unless $found{$_}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Twig - How do I check to see if an element exists in root?
by dbmathis (Scribe) on Jul 05, 2007 at 04:25 UTC | |
by Joost (Canon) on Jul 05, 2007 at 10:39 UTC | |
by dbmathis (Scribe) on Jul 09, 2007 at 17:15 UTC | |
by Joost (Canon) on Jul 14, 2007 at 00:04 UTC | |
by dbmathis (Scribe) on Jul 21, 2007 at 16:25 UTC |