1XML::Parser::Lite(3) User Contributed Perl Documentation XML::Parser::Lite(3)
2
3
4
6 XML::Parser::Lite - Lightweight regexp-based XML parser
7
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
29 This Perl 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 experimantal 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
40 new
41 Constructor.
42
43 As (almost) all SOAP::Lite constructors, new() returns the object
44 called on when called as object method. This means that the following
45 effectifely is a no-op if $obj is a object:
46
47 $obj = $obj->new();
48
49 New accepts a single named parameter, "Handlers" with a hash ref as
50 value:
51
52 my $parser = XML::Parser::Lite->new(
53 Handlers => {
54 Start => sub { shift; print "start: @_\n" },
55 Char => sub { shift; print "char: @_\n" },
56 End => sub { shift; print "end: @_\n" },
57 }
58 );
59
60 The handlers given will be passed to setHandlers.
61
62 setHandlers
63 Sets (or resets) the parsing handlers. Accepts a hash with the handler
64 names and handler code references as parameters. Passing "undef"
65 instead of a code reference replaces the handler by a no-op.
66
67 The following handlers can be set:
68
69 Init
70 Start
71 Char
72 End
73 Final
74
75 All other handlers are ignored.
76
77 Calling setHandlers without parameters resets all handlers to no-ops.
78
79 parse
80 Parses the XML given. In contrast to XML::Parser's parse method,
81 parse() only parses strings.
82
84 Init
85 Called before parsing starts. You should perform any necessary
86 initializations in Init.
87
88 Start
89 Called at the start of each XML node. See XML::Parser for details.
90
91 Char
92 Called for each character sequence. May be called multiple times for
93 the characters contained in an XML node (even for every single
94 character). Your implementation has to make sure that it captures all
95 characters.
96
97 End
98 Called at the end of each XML node. See XML::Parser for details
99
100 Comment
101 See XML::Parser for details
102
103 XMLDecl
104 See XML::Parser for details
105
106 Doctype
107 See XML::Parser for details
108
109 Final
110 Called at the end of the parsing process. You should perform any
111 neccessary cleanup here.
112
114 XML::Parser
115
117 Copyright (C) 2000-2007 Paul Kulchenko. All rights reserved.
118
119 Copyright (C) 2008- Martin Kutter. All rights reserved.
120
121 This library is free software; you can redistribute it and/or modify it
122 under the same terms as Perl itself.
123
124 This parser is based on "shallow parser"
125 http://www.cs.sfu.ca/~cameron/REX.html Copyright (c) 1998, Robert D.
126 Cameron.
127
129 Paul Kulchenko (paulclinger@yahoo.com)
130
131 Martin Kutter (martin.kutter@fen-net.de)
132
133 Additional handlers supplied by Adam Leggett.
134
135
136
137perl v5.12.3 2010-06-03 XML::Parser::Lite(3)