1use Test; 2BEGIN { plan tests => 11 } 3 4use XML::XPath; 5ok(1); 6 7my $xp = XML::XPath->new(ioref => *DATA); 8ok($xp); 9 10my @nodes; 11@nodes = $xp->findnodes('//GGG/ancestor::*'); 12ok(@nodes, 4); 13 14@nodes = $xp->findnodes('//GGG/descendant::*'); 15ok(@nodes, 3); 16 17@nodes = $xp->findnodes('//GGG/following::*'); 18ok(@nodes, 3); 19ok($nodes[0]->getName, "VVV"); 20 21@nodes = $xp->findnodes('//GGG/preceding::*'); 22ok(@nodes, 5); 23ok($nodes[0]->getName, "BBB"); # document order, not HHH 24 25@nodes = $xp->findnodes('//GGG/self::*'); 26ok(@nodes, 1); 27ok($nodes[0]->getName, "GGG"); 28 29@nodes = $xp->findnodes('//GGG/ancestor::* | 30 //GGG/descendant::* | 31 //GGG/following::* | 32 //GGG/preceding::* | 33 //GGG/self::*'); 34ok(@nodes, 16); 35 36__DATA__ 37<AAA> 38 <BBB> 39 <CCC/> 40 <ZZZ/> 41 </BBB> 42 <XXX> 43 <DDD> 44 <EEE/> 45 <FFF> 46 <HHH/> 47 <GGG> <!-- Watch this node --> 48 <JJJ> 49 <QQQ/> 50 </JJJ> 51 <JJJ/> 52 </GGG> 53 <VVV/> 54 </FFF> 55 </DDD> 56 </XXX> 57 <CCC> 58 <DDD/> 59 </CCC> 60</AAA> 61