Debian Codegraph @

README

raw
1 NAME
2 XML::Parser::Lite - Lightweight regexp-based XML parser
3
4 SYNOPSIS
5 use XML::Parser::Lite;
6
7 $p1 = new XML::Parser::Lite;
8 $p1->setHandlers(
9 Start => sub { shift; print "start: @_\n" },
10 Char => sub { shift; print "char: @_\n" },
11 End => sub { shift; print "end: @_\n" },
12 );
13 $p1->parse('<foo id="me">Hello World!</foo>');
14
15 $p2 = new XML::Parser::Lite
16 Handlers => {
17 Start => sub { shift; print "start: @_\n" },
18 Char => sub { shift; print "char: @_\n" },
19 End => sub { shift; print "end: @_\n" },
20 }
21 ;
22 $p2->parse('<foo id="me">Hello <bar>cruel</bar> World!</foo>');
23
24 DESCRIPTION
25 This Perl implements an XML parser with a interface similar to
26 XML::Parser. Though not all callbacks are supported, you should be able
27 to use it in the same way you use XML::Parser. Due to using experimental
28 regexp features it'll work only on Perl 5.6 and above and may behave
29 differently on different platforms.
30
31 Note that you cannot use regular expressions or split in callbacks. This
32 is due to a limitation of perl's regular expression implementation
33 (which is not re-entrant).
34
35 SUBROUTINES/METHODS
36 new
37 Constructor.
38
39 As (almost) all SOAP::Lite constructors, new() returns the object called
40 on when called as object method. This means that the following
41 effectively is a no-op if $obj is a object:
42
43 $obj = $obj->new();
44
45 New accepts a single named parameter, "Handlers" with a hash ref as
46 value:
47
48 my $parser = XML::Parser::Lite->new(
49 Handlers => {
50 Start => sub { shift; print "start: @_\n" },
51 Char => sub { shift; print "char: @_\n" },
52 End => sub { shift; print "end: @_\n" },
53 }
54 );
55
56 The handlers given will be passed to setHandlers.
57
58 setHandlers
59 Sets (or resets) the parsing handlers. Accepts a hash with the handler
60 names and handler code references as parameters. Passing "undef" instead
61 of a code reference replaces the handler by a no-op.
62
63 The following handlers can be set:
64
65 Init
66 Start
67 Char
68 End
69 Final
70
71 All other handlers are ignored.
72
73 Calling setHandlers without parameters resets all handlers to no-ops.
74
75 parse
76 Parses the XML given. In contrast to XML::Parser's parse method, parse()
77 only parses strings.
78
79 Handler methods
80 Init
81 Called before parsing starts. You should perform any necessary
82 initializations in Init.
83
84 Start
85 Called at the start of each XML node. See XML::Parser for details.
86
87 Char
88 Called for each character sequence. May be called multiple times for the
89 characters contained in an XML node (even for every single character).
90 Your implementation has to make sure that it captures all characters.
91
92 End
93 Called at the end of each XML node. See XML::Parser for details
94
95 Comment
96 See XML::Parser for details
97
98 XMLDecl
99 See XML::Parser for details
100
101 Doctype
102 See XML::Parser for details
103
104 Final
105 Called at the end of the parsing process. You should perform any
106 necessary cleanup here.
107
108 SEE ALSO
109 XML::Parser
110
111 COPYRIGHT
112 Copyright (C) 2000-2007 Paul Kulchenko. All rights reserved.
113
114 Copyright (C) 2008 Martin Kutter. All rights reserved.
115
116 Copyright (C) 2013-2015 Fred Moyer. All rights reserved.
117
118 This library is free software; you can redistribute it and/or modify it
119 under the same terms as Perl itself.
120
121 This parser is based on "shallow parser"
122 http://www.cs.sfu.ca/~cameron/REX.html Copyright (c) 1998, Robert D.
123 Cameron.
124
125 AUTHORS
126 Paul Kulchenko ([email protected])
127
128 Martin Kutter ([email protected])
129
130 Fred Moyer ([email protected])
131
132 Additional handlers supplied by Adam Leggett.
133
134 CONTRIBUTORS
135
136 David Steinbrunner ([email protected])
137
138 Neil Bowers ([email protected])
139
140 Paul Cochrane ([email protected])