1XML::Handler::Subs(3) User Contributed Perl DocumentationXML::Handler::Subs(3)
2
3
4
6 XML::Handler::Subs - a PerlSAX handler base class for calling
7 user-defined subs
8
10 use XML::Handler::Subs;
11
12 package MyHandlers;
13 use vars qw{ @ISA };
14
15 sub s_NAME { my ($self, $element) = @_ };
16 sub e_NAME { my ($self, $element) = @_ };
17
18 $self->{Names}; # an array of names
19 $self->{Nodes}; # an array of $element nodes
20
21 $handler = MyHandlers->new();
22 $self->in_element($name);
23 $self->within_element($name);
24
26 "XML::Handler::Subs" is a base class for PerlSAX handlers.
27 "XML::Handler::Subs" is subclassed to implement complete behavior and
28 to add element-specific handling.
29
30 Each time an element starts, a method by that name prefixed with `s_'
31 is called with the element to be processed. Each time an element ends,
32 a method with that name prefixed with `e_' is called. Any special
33 characters in the element name are replaced by underscores.
34
35 Subclassing XML::Handler::Subs in this way is similar to XML::Parser's
36 Subs style.
37
38 XML::Handler::Subs maintains a stack of element names,
39 `"$self-"{Names}', and a stack of element nodes, `"$self-"{Nodes}>'
40 that can be used by subclasses. The current element is pushed on the
41 stacks before calling an element-name start method and popped off the
42 stacks after calling the element-name end method. The `"in_element()"'
43 and `"within_element()"' calls use these stacks.
44
45 If the subclass implements `"start_document()"', `"end_document()"',
46 `"start_element()"', and `"end_element()"', be sure to use `"SUPER::"'
47 to call the the superclass methods also. See perlobj(1) for details on
48 SUPER::. `"SUPER::start_element()"' and `"SUPER::end_element()"'
49 return 1 if an element-name method is called, they return 0 if no
50 method was called.
51
52 XML::Handler::Subs does not implement any other PerlSAX handlers.
53
54 XML::Handler::Subs supports the following methods:
55
56 new( OPTIONS )
57 A basic `"new()"' method. `"new()"' takes a list of key, value
58 pairs or a hash and creates and returns a hash with those options;
59 the hash is blessed into the subclass.
60
61 in_element($name)
62 Returns true if `$name' is equal to the name of the innermost
63 currently opened element.
64
65 within_element($name)
66 Returns the number of times the `$name' appears in Names.
67
69 Ken MacLeod, ken@bitsko.slc.ut.us
70
72 perl(1), PerlSAX.pod(3)
73
74
75
76perl v5.30.1 2020-01-30 XML::Handler::Subs(3)