1XML::Parser::Lite(3)  User Contributed Perl Documentation XML::Parser::Lite(3)
2
3
4

NAME

6       XML::Parser::Lite - Lightweight pure-perl XML Parser (based on regexps)
7

SYNOPSIS

9         use XML::Parser::Lite;
10
11         $p1 = new XML::Parser::Lite;
12         $p1->setHandlers(
13           Start => sub { shift; print "start: @_\n" },
14           Char => sub { shift; print "char: @_\n" },
15           End => sub { shift; print "end: @_\n" },
16         );
17         $p1->parse('<foo id="me">Hello World!</foo>');
18
19         $p2 = new XML::Parser::Lite
20           Handlers => {
21             Start => sub { shift; print "start: @_\n" },
22             Char => sub { shift; print "char: @_\n" },
23             End => sub { shift; print "end: @_\n" },
24           }
25         ;
26         $p2->parse('<foo id="me">Hello <bar>cruel</bar> World!</foo>');
27

DESCRIPTION

29       This module implements an XML parser with a interface similar to
30       XML::Parser. Though not all callbacks are supported, you should be able
31       to use it in the same way you use XML::Parser. Due to using
32       experimental regexp features it'll work only on Perl 5.6 and above and
33       may behave differently on different platforms.
34
35       Note that you cannot use regular expressions or split in callbacks.
36       This is due to a limitation of perl's regular expression implementation
37       (which is not re-entrant).
38

SUBROUTINES/METHODS

40   new
41       Constructor.
42
43       The new() method returns the object called on when called as object
44       method.  This behaviour was inherited from SOAP::Lite, which
45       XML::Parser::Lite was split out from.  This means that the following
46       effectively is a no-op if $obj is a object:
47
48        $obj = $obj->new();
49
50       New accepts a single named parameter, "Handlers" with a hash ref as
51       value:
52
53        my $parser = XML::Parser::Lite->new(
54           Handlers => {
55               Start => sub { shift; print "start: @_\n" },
56               Char => sub { shift; print "char: @_\n" },
57               End => sub { shift; print "end: @_\n" },
58           }
59        );
60
61       The handlers given will be passed to setHandlers.
62
63   setHandlers
64       Sets (or resets) the parsing handlers. Accepts a hash with the handler
65       names and handler code references as parameters. Passing "undef"
66       instead of a code reference replaces the handler by a no-op.
67
68       The following handlers can be set:
69
70        Init
71        Start
72        Char
73        End
74        Final
75
76       All other handlers are ignored.
77
78       Calling setHandlers without parameters resets all handlers to no-ops.
79
80   parse
81       Parses the XML given. In contrast to XML::Parser's parse method,
82       parse() only parses strings.
83

Handler methods

85   Init
86       Called before parsing starts. You should perform any necessary
87       initializations in Init.
88
89   Start
90       Called at the start of each XML node. See XML::Parser for details.
91
92   Char
93       Called for each character sequence. May be called multiple times for
94       the characters contained in an XML node (even for every single
95       character).  Your implementation has to make sure that it captures all
96       characters.
97
98   End
99       Called at the end of each XML node. See XML::Parser for details
100
101   Comment
102       See XML::Parser for details
103
104   XMLDecl
105       See XML::Parser for details
106
107   Doctype
108       See XML::Parser for details
109
110   Final
111       Called at the end of the parsing process. You should perform any
112       necessary cleanup here.
113

SEE ALSO

115       XML::Parser - a full-blown XML Parser, on which XML::Parser::Lite is
116       based.  Requires a C compiler and the expat XML parser.
117
118       XML::Parser::LiteCopy - a fork in XML::Parser::Lite::Tree.
119
120       YAX - another pure-perl module for XML parsing.
121
122       XML::Parser::REX - another module that parses XML with regular
123       expressions.
124
126       Copyright (C) 2000-2007 Paul Kulchenko. All rights reserved.
127
128       Copyright (C) 2008 Martin Kutter. All rights reserved.
129
130       Copyright (C) 2013-2015 Fred Moyer. All rights reserved.
131
132       This library is free software; you can redistribute it and/or modify it
133       under the same terms as Perl itself.
134
135       This parser is based on "shallow parser"
136       <http://www.cs.sfu.ca/~cameron/REX.html> Copyright (c) 1998, Robert D.
137       Cameron.
138

AUTHORS

140       Paul Kulchenko (paulclinger@yahoo.com)
141
142       Martin Kutter (martin.kutter@fen-net.de)
143
144       Fred Moyer (fred@redhotpenguin.com)
145
146       Additional handlers supplied by Adam Leggett.
147

CONTRIBUTORS

149       David Steinbrunner (dsteinbrunner@pobox.com)
150
151       Neil Bowers (neil@bowers.com)
152
153       Paul Cochrane (paul@liekut.de)
154
155
156
157perl v5.30.0                      2019-07-26              XML::Parser::Lite(3)
Impressum