File: dom_jp_cdata.t

package info (click to toggle)
libxml-dom-perl 1.37-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 604 kB
  • ctags: 510
  • sloc: perl: 4,166; xml: 4,117; makefile: 34
file content (49 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download
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
BEGIN {print "1..3\n";}
END {print "not ok 1\n" unless $loaded;}
use XML::DOM;
use CheckAncestors;
use CmpDOM;
$loaded = 1;
print "ok 1\n";

my $test = 1;
sub assert_ok
{
    my $ok = shift;
    print "not " unless $ok;
    ++$test;
    print "ok $test\n";
    $ok;
}

#Test 2

my $str = <<END;
<?xml version="1.0"?>
<テキスト>
<タグ>
    <![CDATA[タグの認識対象としたくないテキストデータ]]>
</タグ>
</テキスト>
END

my $oldStr = <<END;
<?xml version="1.0"?>
<テキスト>
<タグ>
    タグの認識対象としたくないテキストデータ
</タグ>
</テキスト>
END

# Keep CDATASections intact. Without this option set (default), it will convert
# CDATASections to Text nodes. The KeepCDATA option is only supported
# with XML::Parser versions 2.19 and up.
my $parser = new XML::DOM::Parser (KeepCDATA => 1);
my $doc = $parser->parse ($str);
assert_ok (not $@);

my $out = $doc->toString;
$out =~ tr/\012/\n/;
my $result = ($XML::Parser::VERSION >= 2.19) ? $str : $oldStr;
assert_ok ($out eq $result);