File: defaulted.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 (50 lines) | stat: -rw-r--r-- 936 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
45
46
47
48
49
50
BEGIN { print "1..4\n"; }
END { print "not ok 1\n" unless $loaded; }
use XML::Parser;
$loaded = 1;
print "ok 1\n";

$doc = <<'End_of_Doc;';
<!DOCTYPE foo [
<!ATTLIST bar zz CDATA 'there'>
]>
<foo>
  <bar xx="hello"/>
  <bar zz="other"/>
</foo>
End_of_Doc;

sub st {
    my $xp = shift;
    my $el = shift;

    if ( $el eq 'bar' ) {
        my %atts = @_;
        my %isdflt;
        my $specified = $xp->specified_attr;

        for ( my $i = $specified; $i < @_; $i += 2 ) {
            $isdflt{ $_[$i] } = 1;
        }

        if ( defined $atts{xx} ) {
            print 'not '
              if $isdflt{'xx'};
            print "ok 2\n";

            print 'not '
              unless $isdflt{'zz'};
            print "ok 3\n";
        }
        else {
            print 'not '
              if $isdflt{'zz'};
            print "ok 4\n";
        }

    }
}

$p = new XML::Parser( Handlers => { Start => \&st } );

$p->parse($doc);