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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">
<erlref>
<header>
<copyright>
<year>2008</year>
<year>2011</year>
<holder>Ericsson AB, All Rights Reserved</holder>
</copyright>
<legalnotice>
The contents of this file are subject to the Erlang Public License,
Version 1.1, (the "License"); you may not use this file except in
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Initial Developer of the Original Code is Ericsson AB.
</legalnotice>
<title>xmerl_sax_parser</title>
<prepared></prepared>
<docno></docno>
<date></date>
<rev></rev>
</header>
<module>xmerl_sax_parser</module>
<modulesummary>XML SAX parser API</modulesummary>
<description>
<p>
A SAX parser for XML that sends the events through a callback interface.
SAX is the <em>Simple API for XML</em>, originally a Java-only API. SAX was the first widely adopted API for
XML in Java, and is a <em>de facto</em> standard where there are versions for several programming language
environments other than Java.
</p>
</description>
<section>
<title>DATA TYPES</title>
<taglist>
<tag><c>option()</c></tag>
<item>
<p>
Options used to customize the behaviour of the parser.
Possible options are:
</p><p></p>
<taglist>
<tag><c>{continuation_fun, ContinuationFun}</c></tag>
<item>
<seealso marker="#ContinuationFun/1">ContinuationFun</seealso> is a call back function to decide what to do if
the parser runs into EOF before the document is complete.
</item>
<tag><c>{continuation_state, term()}</c></tag>
<item>
State that is accessible in the continuation call back function.
</item>
<tag><c>{event_fun, EventFun}</c></tag>
<item>
<seealso marker="#EventFun/3">EventFun</seealso> is the call back function for parser events.
</item>
<tag><c>{event_state, term()}</c></tag>
<item>
State that is accessible in the event call back function.
</item>
<tag><c>{file_type, FileType}</c></tag>
<item>
Flag that tells the parser if it's parsing a DTD or a normal XML file (default normal).
<list>
<item><c>FileType = normal | dtd</c></item>
</list>
</item>
<tag><c>{encoding, Encoding}</c></tag>
<item>
Set default character set used (default UTF-8). This character set is used only if not explicitly
given by the XML document.
<list>
<item><c>Encoding = utf8 | {utf16,big} | {utf16,little} | latin1 | list</c></item>
</list>
</item>
<tag><c>skip_external_dtd</c></tag>
<item>
Skips the external DTD during parsing.
</item>
</taglist>
</item>
<tag></tag>
<item>
<p></p>
</item>
<tag><c>event()</c></tag>
<item>
<p>
The SAX events that are sent to the user via the callback.
</p><p></p>
<taglist>
<tag><c>startDocument</c></tag>
<item>
Receive notification of the beginning of a document. The SAX parser will send this event only once
before any other event callbacks.
</item>
<tag><c>endDocument</c></tag>
<item>
Receive notification of the end of a document. The SAX parser will send this event only once, and it will
be the last event during the parse.
</item>
<tag><c>{startPrefixMapping, Prefix, Uri}</c></tag>
<item>
Begin the scope of a prefix-URI Namespace mapping.
Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other:
all startPrefixMapping events will occur immediately before the corresponding startElement event, and all
endPrefixMapping events will occur immediately after the corresponding endElement event, but their
order is not otherwise guaranteed.
There will not be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.
<list>
<item><c>Prefix = string()</c></item>
<item><c>Uri = string()</c></item>
</list>
</item>
<tag><c>{endPrefixMapping, Prefix}</c></tag>
<item>
End the scope of a prefix-URI mapping.
<list>
<item><c>Prefix = string()</c></item>
</list>
</item>
<tag><c>{startElement, Uri, LocalName, QualifiedName, Attributes}</c></tag>
<item>
Receive notification of the beginning of an element.
The Parser will send this event at the beginning of every element in the XML document;
there will be a corresponding endElement event for every startElement event (even when the element is empty).
All of the element's content will be reported, in order, before the corresponding endElement event.
<list>
<item><c>Uri = string()</c></item>
<item><c>LocalName = string()</c></item>
<item><c>QualifiedName = {Prefix, LocalName}</c></item>
<item><c>Prefix = string()</c></item>
<item><c>Attributes = [{Uri, Prefix, AttributeName, Value}]</c></item>
<item><c>AttributeName = string()</c></item>
<item><c>Value = string()</c></item>
</list>
</item>
<tag><c>{endElement, Uri, LocalName, QualifiedName}</c></tag>
<item>
Receive notification of the end of an element.
The SAX parser will send this event at the end of every element in the XML document;
there will be a corresponding startElement event for every endElement event (even when the element is empty).
<list>
<item><c>Uri = string()</c></item>
<item><c>LocalName = string()</c></item>
<item><c>QualifiedName = {Prefix, LocalName}</c></item>
<item><c>Prefix = string()</c></item>
</list>
</item>
<tag><c>{characters, string()}</c></tag>
<item>
Receive notification of character data.
</item>
<tag><c>{ignorableWhitespace, string()}</c></tag>
<item>
Receive notification of ignorable whitespace in element content.
</item>
<tag><c>{processingInstruction, Target, Data}</c></tag>
<item>
Receive notification of a processing instruction.
The Parser will send this event once for each processing instruction found:
note that processing instructions may occur before or after the main document element.
<list>
<item><c>Target = string()</c></item>
<item><c>Data = string()</c></item>
</list>
</item>
<tag><c>{comment, string()}</c></tag>
<item>
Report an XML comment anywhere in the document (both inside and outside of the document element).
</item>
<tag><c>startCDATA</c></tag>
<item>
Report the start of a CDATA section. The contents of the CDATA section will be reported
through the regular characters event.
</item>
<tag><c>endCDATA</c></tag>
<item>
Report the end of a CDATA section.
</item>
<tag><c>{startDTD, Name, PublicId, SystemId}</c></tag>
<item>
Report the start of DTD declarations, it's reporting the start of the DOCTYPE declaration.
If the document has no DOCTYPE declaration, this event will not be sent.
<list>
<item><c>Name = string()</c></item>
<item><c>PublicId = string()</c></item>
<item><c>SystemId = string()</c></item>
</list>
</item>
<tag><c>endDTD</c></tag>
<item>
Report the end of DTD declarations, it's reporting the end of the DOCTYPE declaration.
</item>
<tag><c>{startEntity, SysId}</c></tag>
<item>
Report the beginning of some internal and external XML entities. ???
</item>
<tag><c>{endEntity, SysId}</c></tag>
<item>
Report the end of an entity. ???
</item>
<tag><c>{elementDecl, Name, Model}</c></tag>
<item>
Report an element type declaration.
The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group,
optionally followed by an occurrence indicator. The model will be normalized so that all parameter
entities are fully resolved and all whitespace is removed,and will include the enclosing parentheses.
Other normalization (such as removing redundant parentheses or simplifying occurrence indicators)
is at the discretion of the parser.
<list>
<item><c>Name = string()</c></item>
<item><c>Model = string()</c></item>
</list>
</item>
<tag><c>{attributeDecl, ElementName, AttributeName, Type, Mode, Value}</c></tag>
<item>
Report an attribute type declaration.
<list>
<item><c>ElementName = string()</c></item>
<item><c>AttributeName = string()</c></item>
<item><c>Type = string()</c></item>
<item><c>Mode = string()</c></item>
<item><c>Value = string()</c></item>
</list>
</item>
<tag><c>{internalEntityDecl, Name, Value}</c></tag>
<item>
Report an internal entity declaration.
<list>
<item><c>Name = string()</c></item>
<item><c>Value = string()</c></item>
</list>
</item>
<tag><c>{externalEntityDecl, Name, PublicId, SystemId}</c></tag>
<item>
Report a parsed external entity declaration.
<list>
<item><c>Name = string()</c></item>
<item><c>PublicId = string()</c></item>
<item><c>SystemId = string()</c></item>
</list>
</item>
<tag><c>{unparsedEntityDecl, Name, PublicId, SystemId, Ndata}</c></tag>
<item>
Receive notification of an unparsed entity declaration event.
<list>
<item><c>Name = string()</c></item>
<item><c>PublicId = string()</c></item>
<item><c>SystemId = string()</c></item>
<item><c>Ndata = string()</c></item>
</list>
</item>
<tag><c>{notationDecl, Name, PublicId, SystemId}</c></tag>
<item>
Receive notification of a notation declaration event.
<list>
<item><c>Name = string()</c></item>
<item><c>PublicId = string()</c></item>
<item><c>SystemId = string()</c></item>
</list>
</item>
</taglist>
</item>
<tag><c>unicode_char()</c></tag>
<item>
Integer representing valid unicode codepoint.
</item>
<tag><c>unicode_binary()</c></tag>
<item>
Binary with characters encoded in UTF-8 or UTF-16.
</item>
<tag><c>latin1_binary()</c></tag>
<item>
Binary with characters encoded in iso-latin-1.
</item>
</taglist>
</section>
<funcs>
<func>
<name>file(Filename, Options) -> Result</name>
<fsummary>Parse file containing an XML document.</fsummary>
<type>
<v>Filename = string()</v>
<v>Options = [option()]</v>
<v>Result = {ok, EventState, Rest} |</v>
<v> {Tag, Location, Reason, EndTags, EventState}</v>
<v>Rest = unicode_binary() | latin1_binary()</v>
<v>Tag = atom() (fatal_error, or user defined tag)</v>
<v>Location = {CurrentLocation, EntityName, LineNo}</v>
<v>CurrentLocation = string()</v>
<v>EntityName = string()</v>
<v>LineNo = integer()</v>
<v>EventState = term()</v>
<v>Reason = term()</v>
</type>
<desc>
<p>Parse file containing an XML document. This functions uses a default continuation function to read the file in blocks.</p>
</desc>
</func>
<func>
<name>stream(Xml, Options) -> Result</name>
<fsummary>Parse a stream containing an XML document.</fsummary>
<type>
<v>Xml = unicode_binary() | latin1_binary() | [unicode_char()]</v>
<v>Options = [option()]</v>
<v>Result = {ok, EventState, Rest} |</v>
<v> {Tag, Location, Reason, EndTags, EventState}</v>
<v>Rest = unicode_binary() | latin1_binary() | [unicode_char()]</v>
<v>Tag = atom() (fatal_error or user defined tag)</v>
<v>Location = {CurrentLocation, EntityName, LineNo}</v>
<v>CurrentLocation = string()</v>
<v>EntityName = string()</v>
<v>LineNo = integer()</v>
<v>EventState = term()</v>
<v>Reason = term()</v>
</type>
<desc>
<p>Parse a stream containing an XML document.</p>
</desc>
</func>
</funcs>
<section>
<title>CALLBACK FUNCTIONS</title>
<p>
The callback interface is based on that the user sends a fun with the
correct signature to the parser.
</p>
</section>
<funcs>
<func>
<name>ContinuationFun(State) -> {NewBytes, NewState}</name>
<fsummary>Continuation call back function.</fsummary>
<type>
<v>State = NewState = term()</v>
<v>NewBytes = binary() | list() (should be same as start input in stream/2)</v>
</type>
<desc>
<p>
This function is called whenever the parser runs out of input data.
If the function can't get hold of more input an empty list or binary
(depends on start input in stream/2) is returned.
Other types of errors is handled through exceptions. Use throw/1 to send the
following tuple {Tag = atom(), Reason = string()} if the continuation function encounters a fatal error.
Tag is an atom that identifies the functional entity that sends the exception
and Reason is a string that describes the problem.
</p>
</desc>
</func>
<func>
<name>EventFun(Event, Location, State) -> NewState</name>
<fsummary>Event call back function.</fsummary>
<type>
<v>Event = event()</v>
<v>Location = {CurrentLocation, Entityname, LineNo}</v>
<v>CurrentLocation = string()</v>
<v>Entityname = string()</v>
<v>LineNo = integer()</v>
<v>State = NewState = term()</v>
</type>
<desc>
<p>
This function is called for every event sent by the parser.
The error handling is done through exceptions. Use throw/1 to send the
following tuple {Tag = atom(), Reason = string()} if the application encounters a fatal error.
Tag is an atom that identifies the functional entity that sends the exception
and Reason is a string that describes the problem.
</p>
</desc>
</func>
</funcs>
</erlref>
|