File: 47position.t

package info (click to toggle)
libxml-xpath-perl 1.48-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 608 kB
  • sloc: perl: 4,444; xml: 34; makefile: 10
file content (48 lines) | stat: -rw-r--r-- 1,357 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main;

use strict;
use warnings;
use Data::Dumper;
use Test::More; # tests => 5;

#use XML::XPath;
use_ok("XML::XPath");

my $path = XML::XPath->new(ioref => \*DATA);

$path->createNode("/child::foo/child::bar/child::baz");
$path->setNodeText("/child::foo/child::bar/child::baz[position()=last()]", "blah");
$path->setNodeText("/child::foo/child::bar/child::baz[position()=last()]/attribute::id", "id0");

$path->createNode("/child::foo/child::bar/child::baz[position()=3]");
$path->setNodeText("/child::foo/child::bar/child::baz[position()=last()]", "blah 2");
$path->setNodeText("/child::foo/child::bar/child::baz[position()=last()]/\@id", "id1");

my $set = $path->find("/foo/bar/baz");
my @nodelist = $set->get_nodelist;

#print Dumper($nodelist[0]);
#print $nodelist[0]->toString, "\n";
#print $nodelist[1]->toString, "\n";
#print $nodelist[2]->toString, "\n";

ok(defined $nodelist[0]);
ok(defined $nodelist[1]);
ok(defined $nodelist[2]);

ok($nodelist[0]->toString =~ /id="id0"/);
ok(defined $nodelist[1] && $nodelist[1]->toString !~ /id/);
ok(defined $nodelist[2] && $nodelist[2]->toString =~ /id="id1"/);

$path->createNode("/child::foo/child::bar/child::baz[5]");
$set = $path->find("/foo/bar/baz");
@nodelist = $set->get_nodelist;

is(scalar(@nodelist), 5);

done_testing();

__DATA__
<?xml version="1.0" ?>
<instanceData>
</instanceData>