File: Perl2SAX.pm

package info (click to toggle)
libxml-perl 0.08-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 488 kB
  • sloc: perl: 1,961; xml: 301; sh: 31; makefile: 2
file content (120 lines) | stat: -rw-r--r-- 2,576 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# Copyright (C) 1998 Ken MacLeod
# XML::Perl2SAX is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# $Id: Perl2SAX.pm,v 1.3 1999/12/22 21:15:00 kmacleod Exp $
#

use strict;

package XML::Perl2SAX;

use vars qw{ $VERSION };

# will be substituted by make-rel script
$VERSION = "0.08";

sub new {
    my $type = shift;
    my $self = ($#_ == 0) ? shift : { @_ };

    return bless $self, $type;
}

sub start_document {
    my $self = shift;
    my $properties = ($#_ == 0) ? shift : { @_ };

    if ($properties->{Locator}) {
	$self->{DocumentHandler}->setDocumentLocator($properties->{Locator});
    }

    $self->{DocumentHandler}->startDocument;
}

sub end_document {
    my $self = shift;

    $self->{DocumentHandler}->endDocument;
}

sub start_element {
    my $self = shift;
    my $properties = shift;

    # FIXME depends on how Perl SAX treats attributes
    $self->{DocumentHandler}->startElement($properties->{Name},
					   $properties->{Attributes});
}

sub end_element {
    my $self = shift;
    my $properties = shift;

    $self->{DocumentHandler}->endElement($properties->{Name});
}

sub characters {
    my $self = shift;
    my $properties = shift;

    $self->{DocumentHandler}->characters($properties->{Data},
					 0,
					 length($properties->{Data}));
}

sub ignorable_whitespace {
    my $self = shift;
    my $properties = shift;

    $self->{DocumentHandler}->ignorableWhitespace($properties->{Data},
						  0,
						  length($properties->{Data}));
}

sub processing_instruction {
    my $self = shift;
    my $properties = shift;

    $self->{DocumentHandler}->processingInstruction($properties->{Target},
						    $properties->{Data});
}

1;

__END__

=head1 NAME

XML::SAX2Perl -- translate Perl SAX methods to Java/CORBA style methods

=head1 SYNOPSIS

 use XML::Perl2SAX;

 $perl2sax = XML::Perl2SAX(handler => $java_style_handler);

=head1 DESCRIPTION

C<XML::Perl2SAX> is a SAX filter that translates Perl style SAX
methods to Java/CORBA style method calls.  This module performs the
inverse operation from C<XML::SAX2Perl>.

C<Perl2SAX> is a Perl SAX document handler.  The `C<new>' method takes
a `C<handler>' argument that is a Java/CORBA style handler that the
new Perl2SAX instance will call.  The SAX interfaces are defined at
<http://www.megginson.com/SAX/>.

=head1 AUTHOR

Ken MacLeod <ken@bitsko.slc.ut.us>

=head1 SEE ALSO

perl(1), XML::Perl2SAX(3).

 Extensible Markup Language (XML) <http://www.w3c.org/XML/>
 Simple API for XML (SAX) <http://www.megginson.com/SAX/>

=cut