Another way ... :-)
#!/usr/bin/perl -w use strict; use warnings; my $filename = 'library.xml'; use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($filename); print "\nBooks\n"; my @nodes = $doc->findnodes("/library/book[last()]"); foreach my $node (@nodes) { print $node->findvalue( 'title')."\n"; my @authors = $node->findnodes('author'); print "Authors:".scalar(@authors)."\n"; foreach my $auth (@authors) { print $auth->textContent()."\n"; } }
In reply to Re: perl & XML: getting last child?
by space_monk
in thread perl & XML: getting last child?
by ambrill
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |