File: cdata.t

package info (click to toggle)
libxml-parser-perl 2.47-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: xml: 3,937; perl: 2,026; makefile: 38; ansic: 27
file content (44 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (4)
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
BEGIN { print "1..2\n"; }
END { print "not ok 1\n" unless $loaded; }
use XML::Parser;
$loaded = 1;
print "ok 1\n";

my $count = 0;

my $cdata_part = "<<< & > '' << &&&>&&&&;<";

my $doc = "<foo> hello <![CDATA[$cdata_part]]> there</foo>";

my $acc = '';

sub ch {
    my ( $xp, $data ) = @_;

    $acc .= $data;
}

sub stcd {
    my $xp = shift;
    $xp->setHandlers( Char => \&ch );
}

sub ecd {
    my $xp = shift;
    $xp->setHandlers( Char => 0 );
}

$parser = new XML::Parser(
    ErrorContext => 2,
    Handlers     => {
        CdataStart => \&stcd,
        CdataEnd   => \&ecd
    }
);

$parser->parse($doc);

print "not "
  unless ( $acc eq $cdata_part );
print "ok 2\n";