XML parsing with Perl using XPath

use strict;
use XML::LibXML;

# data source
my $xml_filename = "xml/data.xml";

my $parser = XML::LibXML->new;
my $doc = $parser->parse_file($xml_filename);

my $xpath = "//word/entry[\@src=\"pr\"]/..";
my @words = $doc->findnodes($xpath);

foreach my $word (@words) {
	print $word->findvalue("\@id");
	print "\n";
}
This entry was posted in Data Processing, Programming, Tips & Tricks and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>