File: xpath.pl

package info (click to toggle)
libxml-hash-lx-perl 0.0603-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: perl: 2,603; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 432 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env perl

use strict;
use lib::abs '../lib';
use XML::LibXML;
use XML::Hash::LX;
use Data::Dumper;

my $xml = do 'xml.pl';

# parse in common way
my $doc = XML::LibXML->new->parse_string($xml);
my $xp  = XML::LibXML::XPathContext->new($doc);
$xp->registerNs('rss', 'http://purl.org/rss/1.0/');

# then process xpath
for ($xp->findnodes('//rss:item')) {
	# and convert to hash concrete nodes
	print Dumper+xml2hash($_);
}