in reply to Is it possible to parse an XML file recursively using XML::Twig?
I like XPath and found some XPath solutions to the problem on stackoverflow here including this one: //*[not(child::*)]. XML::Twig didn't seem to handle the XPath expressions on stackoverflow but XML::XPath did. XML::XPath also comes with an 'xpath' grep like utility that might give you a solution as simple as:
xpath -e '//*[not(child::*)]' books.xml
If you want to do Perl coding for further processing the solution is still pretty simple
use strict; use warnings; use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => 'books.xml'); my $nodeset = $xp->find('//*[not(child::*)]'); foreach my $node ($nodeset->get_nodelist) { print "FOUND:", XML::XPath::XMLParser::as_string($node), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to parse an XML file recursively using XML::Twig?
by Jenda (Abbot) on Oct 21, 2015 at 16:27 UTC | |
|
Re^2: Is it possible to parse an XML file recursively using XML::Twig?
by Ppeoc (Beadle) on Oct 30, 2015 at 17:57 UTC |