File: 50_xpath.t

package info (click to toggle)
libxml-dt-perl 0.69-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 388 kB
  • sloc: perl: 1,432; xml: 438; makefile: 16
file content (52 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (7)
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
49
50
51
52
# -*- cperl -*-

use Test::More tests => 12;
use XML::DT;

### XPath over elements

my $xml = <<"EOX";
<a><b><c>1</c></b><c>2</c><b><c>3</c></b></a>
EOX

# identity 1
is (pathdtstring($xml, (-default => sub{toxml} ))."\n", $xml);

# identity 2
is (pathdtstring($xml, ("//*" => sub{toxml} ))."\n", $xml);

is (pathdtstring($xml, ("//c"    => sub{"$c"},
			-default => sub{toxml})),
    "<a><b>1</b>2<b>3</b></a>");

is (pathdtstring($xml, ("/c" => sub{"$c"},
			"-default" => sub{toxml}))."\n", $xml);

is (pathdtstring($xml, ("/*/*/c" => sub{"$c"},
			"-default" => sub{toxml})),
    "<a><b>1</b><c>2</c><b>3</b></a>");

is (pathdtstring($xml, ("/*" => sub{"$q"})), "a");

is (pathdtstring($xml, ("a|b|c" => sub{toxml} ))."\n", $xml);

### XPath over attributes

$xml = <<"EOX";
<a v="1"><b>2</b><c><b>3</b></c><a v="2">4</a></a>
EOX

#identity 1
is (pathdtstring($xml, (-default => sub{toxml} ))."\n", $xml);

#identity 2
is (pathdtstring($xml, ("//*" => sub{toxml} ))."\n", $xml);

is (pathdtstring($xml, ("//*[@*]" => sub{toxml($q,{},$c)})),
    "<a><b>2</b><c><b>3</b></c><a>4</a></a>");

is (pathdtstring($xml, ("//a[\@v='2']" => sub{toxml($q,{},$c)},
			"//*" => sub{toxml})),
    "<a v=\"1\"><b>2</b><c><b>3</b></c><a>4</a></a>");

is (pathdtstring($xml, ("//a[\@v='1']" => sub{"zbr"})), "zbr");