1#!/usr/bin/perl 2 3use Test; 4BEGIN { plan tests => 8 } 5 6use XML::XPath; 7use XML::XPath::Node::Comment; 8#$XML::XPath::SafeMode = 1; 9 10ok(1); 11my $xp = XML::XPath->new(ioref => *DATA); 12ok($xp); 13 14my ($root) = $xp->findnodes('/'); 15 16ok($root); 17 18($root) = $root->getChildNodes; 19my @nodes = $root->findnodes('//Cart'); 20 21ok(@nodes, 2); 22 23my $comment = XML::XPath::Node::Comment->new("Before Comment"); 24 25$root->insertBefore($comment, $nodes[0]); 26 27my $other_comment = XML::XPath::Node::Comment->new("After Comment"); 28 29$root->insertAfter($other_comment, $nodes[0]); 30 31@nodes = $xp->findnodes('/Shop/node()'); 32 33# foreach (@nodes) { 34# print STDERR $_->toString; 35# } 36 37ok($nodes[1]->isCommentNode); 38ok($nodes[3]->isCommentNode); 39 40my ($before) = $xp->findnodes('/Shop/comment()[contains( string() , "Before")]'); 41ok($before->get_pos, 1); 42 43my ($after) = $xp->findnodes('/Shop/comment()[contains( string() , "After")]'); 44ok($after->get_pos, 3); 45 46 47__DATA__ 48<Shop id="mod3838" hello="you"> 49<Cart id="1" crap="crap"> 50 <Item id="11" crap="crap"/> 51</Cart> 52<Cart id="2" crap="crap"/> 53</Shop> 54