]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/expat/xmlparse/xmlparse.h
fix for focus handling when deleting the items
[wxWidgets.git] / src / xrc / expat / xmlparse / xmlparse.h
CommitLineData
78d14f80
VS
1/*
2Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
3See the file copying.txt for copying permission.
4*/
5
6#ifndef XmlParse_INCLUDED
7#define XmlParse_INCLUDED 1
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#ifndef XMLPARSEAPI
14#define XMLPARSEAPI /* as nothing */
15#endif
16
17typedef void *XML_Parser;
18
19#ifdef XML_UNICODE_WCHAR_T
20
21/* XML_UNICODE_WCHAR_T will work only if sizeof(wchar_t) == 2 and wchar_t
22uses Unicode. */
23/* Information is UTF-16 encoded as wchar_ts */
24
25#ifndef XML_UNICODE
26#define XML_UNICODE
27#endif
28
29#include <stddef.h>
30typedef wchar_t XML_Char;
31typedef wchar_t XML_LChar;
32
33#else /* not XML_UNICODE_WCHAR_T */
34
35#ifdef XML_UNICODE
36
37/* Information is UTF-16 encoded as unsigned shorts */
38typedef unsigned short XML_Char;
39typedef char XML_LChar;
40
41#else /* not XML_UNICODE */
42
43/* Information is UTF-8 encoded. */
44typedef char XML_Char;
45typedef char XML_LChar;
46
47#endif /* not XML_UNICODE */
48
49#endif /* not XML_UNICODE_WCHAR_T */
50
51
52/* Constructs a new parser; encoding is the encoding specified by the external
53protocol or null if there is none specified. */
54
55XML_Parser XMLPARSEAPI
56XML_ParserCreate(const XML_Char *encoding);
57
58/* Constructs a new parser and namespace processor. Element type names
59and attribute names that belong to a namespace will be expanded;
60unprefixed attribute names are never expanded; unprefixed element type
61names are expanded only if there is a default namespace. The expanded
62name is the concatenation of the namespace URI, the namespace separator character,
63and the local part of the name. If the namespace separator is '\0' then
64the namespace URI and the local part will be concatenated without any
65separator. When a namespace is not declared, the name and prefix will be
66passed through without expansion. */
67
68XML_Parser XMLPARSEAPI
69XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
70
71
72/* atts is array of name/value pairs, terminated by 0;
73 names and values are 0 terminated. */
74
75typedef void (*XML_StartElementHandler)(void *userData,
76 const XML_Char *name,
77 const XML_Char **atts);
78
79typedef void (*XML_EndElementHandler)(void *userData,
80 const XML_Char *name);
81
82/* s is not 0 terminated. */
83typedef void (*XML_CharacterDataHandler)(void *userData,
84 const XML_Char *s,
85 int len);
86
87/* target and data are 0 terminated */
88typedef void (*XML_ProcessingInstructionHandler)(void *userData,
89 const XML_Char *target,
90 const XML_Char *data);
91
92/* data is 0 terminated */
93typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
94
95typedef void (*XML_StartCdataSectionHandler)(void *userData);
96typedef void (*XML_EndCdataSectionHandler)(void *userData);
97
98/* This is called for any characters in the XML document for
99which there is no applicable handler. This includes both
100characters that are part of markup which is of a kind that is
101not reported (comments, markup declarations), or characters
102that are part of a construct which could be reported but
103for which no handler has been supplied. The characters are passed
104exactly as they were in the XML document except that
105they will be encoded in UTF-8. Line boundaries are not normalized.
106Note that a byte order mark character is not passed to the default handler.
107There are no guarantees about how characters are divided between calls
108to the default handler: for example, a comment might be split between
109multiple calls. */
110
111typedef void (*XML_DefaultHandler)(void *userData,
112 const XML_Char *s,
113 int len);
114
115/* This is called for the start of the DOCTYPE declaration when the
116name of the DOCTYPE is encountered. */
117typedef void (*XML_StartDoctypeDeclHandler)(void *userData,
118 const XML_Char *doctypeName);
119
120/* This is called for the start of the DOCTYPE declaration when the
121closing > is encountered, but after processing any external subset. */
122typedef void (*XML_EndDoctypeDeclHandler)(void *userData);
123
124/* This is called for a declaration of an unparsed (NDATA)
125entity. The base argument is whatever was set by XML_SetBase.
126The entityName, systemId and notationName arguments will never be null.
127The other arguments may be. */
128
129typedef void (*XML_UnparsedEntityDeclHandler)(void *userData,
130 const XML_Char *entityName,
131 const XML_Char *base,
132 const XML_Char *systemId,
133 const XML_Char *publicId,
134 const XML_Char *notationName);
135
136/* This is called for a declaration of notation.
137The base argument is whatever was set by XML_SetBase.
138The notationName will never be null. The other arguments can be. */
139
140typedef void (*XML_NotationDeclHandler)(void *userData,
141 const XML_Char *notationName,
142 const XML_Char *base,
143 const XML_Char *systemId,
144 const XML_Char *publicId);
145
146typedef void (*XML_ExternalParsedEntityDeclHandler)(void *userData,
147 const XML_Char *entityName,
148 const XML_Char *base,
149 const XML_Char *systemId,
150 const XML_Char *publicId);
151
152typedef void (*XML_InternalParsedEntityDeclHandler)(void *userData,
153 const XML_Char *entityName,
154 const XML_Char *replacementText,
155 int replacementTextLength);
156
157/* When namespace processing is enabled, these are called once for
158each namespace declaration. The call to the start and end element
159handlers occur between the calls to the start and end namespace
160declaration handlers. For an xmlns attribute, prefix will be null.
161For an xmlns="" attribute, uri will be null. */
162
163typedef void (*XML_StartNamespaceDeclHandler)(void *userData,
164 const XML_Char *prefix,
165 const XML_Char *uri);
166
167typedef void (*XML_EndNamespaceDeclHandler)(void *userData,
168 const XML_Char *prefix);
169
170/* This is called if the document is not standalone (it has an
171external subset or a reference to a parameter entity, but does not
172have standalone="yes"). If this handler returns 0, then processing
173will not continue, and the parser will return a
174XML_ERROR_NOT_STANDALONE error. */
175
176typedef int (*XML_NotStandaloneHandler)(void *userData);
177
178/* This is called for a reference to an external parsed general entity.
179The referenced entity is not automatically parsed.
180The application can parse it immediately or later using
181XML_ExternalEntityParserCreate.
182The parser argument is the parser parsing the entity containing the reference;
183it can be passed as the parser argument to XML_ExternalEntityParserCreate.
184The systemId argument is the system identifier as specified in the entity declaration;
185it will not be null.
186The base argument is the system identifier that should be used as the base for
187resolving systemId if systemId was relative; this is set by XML_SetBase;
188it may be null.
189The publicId argument is the public identifier as specified in the entity declaration,
190or null if none was specified; the whitespace in the public identifier
191will have been normalized as required by the XML spec.
192The context argument specifies the parsing context in the format
193expected by the context argument to
194XML_ExternalEntityParserCreate; context is valid only until the handler
195returns, so if the referenced entity is to be parsed later, it must be copied.
196The handler should return 0 if processing should not continue because of
197a fatal error in the handling of the external entity.
198In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING
199error.
200Note that unlike other handlers the first argument is the parser, not userData. */
201
202typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser,
203 const XML_Char *context,
204 const XML_Char *base,
205 const XML_Char *systemId,
206 const XML_Char *publicId);
207
208/* This structure is filled in by the XML_UnknownEncodingHandler
209to provide information to the parser about encodings that are unknown
210to the parser.
211The map[b] member gives information about byte sequences
212whose first byte is b.
213If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar value c.
214If map[b] is -1, then the byte sequence is malformed.
215If map[b] is -n, where n >= 2, then b is the first byte of an n-byte
216sequence that encodes a single Unicode scalar value.
217The data member will be passed as the first argument to the convert function.
218The convert function is used to convert multibyte sequences;
219s will point to a n-byte sequence where map[(unsigned char)*s] == -n.
220The convert function must return the Unicode scalar value
221represented by this byte sequence or -1 if the byte sequence is malformed.
222The convert function may be null if the encoding is a single-byte encoding,
223that is if map[b] >= -1 for all bytes b.
224When the parser is finished with the encoding, then if release is not null,
225it will call release passing it the data member;
226once release has been called, the convert function will not be called again.
227
228Expat places certain restrictions on the encodings that are supported
229using this mechanism.
230
2311. Every ASCII character that can appear in a well-formed XML document,
232other than the characters
233
234 $@\^`{}~
235
236must be represented by a single byte, and that byte must be the
237same byte that represents that character in ASCII.
238
2392. No character may require more than 4 bytes to encode.
240
2413. All characters encoded must have Unicode scalar values <= 0xFFFF,
242(ie characters that would be encoded by surrogates in UTF-16
243are not allowed). Note that this restriction doesn't apply to
244the built-in support for UTF-8 and UTF-16.
245
2464. No Unicode character may be encoded by more than one distinct sequence
247of bytes. */
248
249typedef struct {
250 int map[256];
251 void *data;
252 int (*convert)(void *data, const char *s);
253 void (*release)(void *data);
254} XML_Encoding;
255
256/* This is called for an encoding that is unknown to the parser.
257The encodingHandlerData argument is that which was passed as the
258second argument to XML_SetUnknownEncodingHandler.
259The name argument gives the name of the encoding as specified in
260the encoding declaration.
261If the callback can provide information about the encoding,
262it must fill in the XML_Encoding structure, and return 1.
263Otherwise it must return 0.
264If info does not describe a suitable encoding,
265then the parser will return an XML_UNKNOWN_ENCODING error. */
266
267typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
268 const XML_Char *name,
269 XML_Encoding *info);
270
271void XMLPARSEAPI
272XML_SetElementHandler(XML_Parser parser,
273 XML_StartElementHandler start,
274 XML_EndElementHandler end);
275
276void XMLPARSEAPI
277XML_SetCharacterDataHandler(XML_Parser parser,
278 XML_CharacterDataHandler handler);
279
280void XMLPARSEAPI
281XML_SetProcessingInstructionHandler(XML_Parser parser,
282 XML_ProcessingInstructionHandler handler);
283void XMLPARSEAPI
284XML_SetCommentHandler(XML_Parser parser,
285 XML_CommentHandler handler);
286
287void XMLPARSEAPI
288XML_SetCdataSectionHandler(XML_Parser parser,
289 XML_StartCdataSectionHandler start,
290 XML_EndCdataSectionHandler end);
291
292/* This sets the default handler and also inhibits expansion of internal entities.
293The entity reference will be passed to the default handler. */
294
295void XMLPARSEAPI
296XML_SetDefaultHandler(XML_Parser parser,
297 XML_DefaultHandler handler);
298
299/* This sets the default handler but does not inhibit expansion of internal entities.
300The entity reference will not be passed to the default handler. */
301
302void XMLPARSEAPI
303XML_SetDefaultHandlerExpand(XML_Parser parser,
304 XML_DefaultHandler handler);
305
306void XMLPARSEAPI
307XML_SetDoctypeDeclHandler(XML_Parser parser,
308 XML_StartDoctypeDeclHandler start,
309 XML_EndDoctypeDeclHandler end);
310
311void XMLPARSEAPI
312XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
313 XML_UnparsedEntityDeclHandler handler);
314
315void XMLPARSEAPI
316XML_SetNotationDeclHandler(XML_Parser parser,
317 XML_NotationDeclHandler handler);
318
319void XMLPARSEAPI
320XML_SetExternalParsedEntityDeclHandler(XML_Parser parser,
321 XML_ExternalParsedEntityDeclHandler handler);
322
323void XMLPARSEAPI
324XML_SetInternalParsedEntityDeclHandler(XML_Parser parser,
325 XML_InternalParsedEntityDeclHandler handler);
326
327void XMLPARSEAPI
328XML_SetNamespaceDeclHandler(XML_Parser parser,
329 XML_StartNamespaceDeclHandler start,
330 XML_EndNamespaceDeclHandler end);
331
332void XMLPARSEAPI
333XML_SetNotStandaloneHandler(XML_Parser parser,
334 XML_NotStandaloneHandler handler);
335
336void XMLPARSEAPI
337XML_SetExternalEntityRefHandler(XML_Parser parser,
338 XML_ExternalEntityRefHandler handler);
339
340/* If a non-null value for arg is specified here, then it will be passed
341as the first argument to the external entity ref handler instead
342of the parser object. */
343void XMLPARSEAPI
344XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg);
345
346void XMLPARSEAPI
347XML_SetUnknownEncodingHandler(XML_Parser parser,
348 XML_UnknownEncodingHandler handler,
349 void *encodingHandlerData);
350
351/* This can be called within a handler for a start element, end element,
352processing instruction or character data. It causes the corresponding
353markup to be passed to the default handler. */
354void XMLPARSEAPI XML_DefaultCurrent(XML_Parser parser);
355
356/* This value is passed as the userData argument to callbacks. */
357void XMLPARSEAPI
358XML_SetUserData(XML_Parser parser, void *userData);
359
360/* Returns the last value set by XML_SetUserData or null. */
361#define XML_GetUserData(parser) (*(void **)(parser))
362
363/* This is equivalent to supplying an encoding argument
364to XML_ParserCreate. It must not be called after XML_Parse
365or XML_ParseBuffer. */
366
367int XMLPARSEAPI
368XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
369
370/* If this function is called, then the parser will be passed
371as the first argument to callbacks instead of userData.
372The userData will still be accessible using XML_GetUserData. */
373
374void XMLPARSEAPI
375XML_UseParserAsHandlerArg(XML_Parser parser);
376
377/* Sets the base to be used for resolving relative URIs in system identifiers in
378declarations. Resolving relative identifiers is left to the application:
379this value will be passed through as the base argument to the
380XML_ExternalEntityRefHandler, XML_NotationDeclHandler
381and XML_UnparsedEntityDeclHandler. The base argument will be copied.
382Returns zero if out of memory, non-zero otherwise. */
383
384int XMLPARSEAPI
385XML_SetBase(XML_Parser parser, const XML_Char *base);
386
387const XML_Char XMLPARSEAPI *
388XML_GetBase(XML_Parser parser);
389
390/* Returns the number of the attribute/value pairs passed in last call
391to the XML_StartElementHandler that were specified in the start-tag
392rather than defaulted. Each attribute/value pair counts as 2; thus
393this correspondds to an index into the atts array passed to the
394XML_StartElementHandler. */
395
396int XMLPARSEAPI XML_GetSpecifiedAttributeCount(XML_Parser parser);
397
398/* Returns the index of the ID attribute passed in the last call to
399XML_StartElementHandler, or -1 if there is no ID attribute. Each
400attribute/value pair counts as 2; thus this correspondds to an index
401into the atts array passed to the XML_StartElementHandler. */
402int XMLPARSEAPI XML_GetIdAttributeIndex(XML_Parser parser);
403
404/* Parses some input. Returns 0 if a fatal error is detected.
405The last call to XML_Parse must have isFinal true;
406len may be zero for this call (or any other). */
407int XMLPARSEAPI
408XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
409
410void XMLPARSEAPI *
411XML_GetBuffer(XML_Parser parser, int len);
412
413int XMLPARSEAPI
414XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
415
416/* Creates an XML_Parser object that can parse an external general entity;
417context is a '\0'-terminated string specifying the parse context;
418encoding is a '\0'-terminated string giving the name of the externally specified encoding,
419or null if there is no externally specified encoding.
420The context string consists of a sequence of tokens separated by formfeeds (\f);
421a token consisting of a name specifies that the general entity of the name
422is open; a token of the form prefix=uri specifies the namespace for a particular
423prefix; a token of the form =uri specifies the default namespace.
424This can be called at any point after the first call to an ExternalEntityRefHandler
425so longer as the parser has not yet been freed.
426The new parser is completely independent and may safely be used in a separate thread.
427The handlers and userData are initialized from the parser argument.
428Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */
429XML_Parser XMLPARSEAPI
430XML_ExternalEntityParserCreate(XML_Parser parser,
431 const XML_Char *context,
432 const XML_Char *encoding);
433
434enum XML_ParamEntityParsing {
435 XML_PARAM_ENTITY_PARSING_NEVER,
436 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
437 XML_PARAM_ENTITY_PARSING_ALWAYS
438};
439
440/* Controls parsing of parameter entities (including the external DTD
441subset). If parsing of parameter entities is enabled, then references
442to external parameter entities (including the external DTD subset)
443will be passed to the handler set with
444XML_SetExternalEntityRefHandler. The context passed will be 0.
445Unlike external general entities, external parameter entities can only
446be parsed synchronously. If the external parameter entity is to be
447parsed, it must be parsed during the call to the external entity ref
448handler: the complete sequence of XML_ExternalEntityParserCreate,
449XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
450this call. After XML_ExternalEntityParserCreate has been called to
451create the parser for the external parameter entity (context must be 0
452for this call), it is illegal to make any calls on the old parser
453until XML_ParserFree has been called on the newly created parser. If
454the library has been compiled without support for parameter entity
455parsing (ie without XML_DTD being defined), then
456XML_SetParamEntityParsing will return 0 if parsing of parameter
457entities is requested; otherwise it will return non-zero. */
458
459int XMLPARSEAPI
460XML_SetParamEntityParsing(XML_Parser parser,
461 enum XML_ParamEntityParsing parsing);
462
463enum XML_Error {
464 XML_ERROR_NONE,
465 XML_ERROR_NO_MEMORY,
466 XML_ERROR_SYNTAX,
467 XML_ERROR_NO_ELEMENTS,
468 XML_ERROR_INVALID_TOKEN,
469 XML_ERROR_UNCLOSED_TOKEN,
470 XML_ERROR_PARTIAL_CHAR,
471 XML_ERROR_TAG_MISMATCH,
472 XML_ERROR_DUPLICATE_ATTRIBUTE,
473 XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
474 XML_ERROR_PARAM_ENTITY_REF,
475 XML_ERROR_UNDEFINED_ENTITY,
476 XML_ERROR_RECURSIVE_ENTITY_REF,
477 XML_ERROR_ASYNC_ENTITY,
478 XML_ERROR_BAD_CHAR_REF,
479 XML_ERROR_BINARY_ENTITY_REF,
480 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
481 XML_ERROR_MISPLACED_XML_PI,
482 XML_ERROR_UNKNOWN_ENCODING,
483 XML_ERROR_INCORRECT_ENCODING,
484 XML_ERROR_UNCLOSED_CDATA_SECTION,
485 XML_ERROR_EXTERNAL_ENTITY_HANDLING,
486 XML_ERROR_NOT_STANDALONE
487};
488
489/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
490returns information about the error. */
491
492enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser);
493
494/* These functions return information about the current parse location.
495They may be called when XML_Parse or XML_ParseBuffer return 0;
496in this case the location is the location of the character at which
497the error was detected.
498They may also be called from any other callback called to report
499some parse event; in this the location is the location of the first
500of the sequence of characters that generated the event. */
501
502int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser);
503int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser);
504long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser);
505
506/* Return the number of bytes in the current event.
507Returns 0 if the event is in an internal entity. */
508
509int XMLPARSEAPI XML_GetCurrentByteCount(XML_Parser parser);
510
511/* For backwards compatibility with previous versions. */
512#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
513#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
514#define XML_GetErrorByteIndex XML_GetCurrentByteIndex
515
516/* Frees memory used by the parser. */
517void XMLPARSEAPI
518XML_ParserFree(XML_Parser parser);
519
520/* Returns a string describing the error. */
521const XML_LChar XMLPARSEAPI *XML_ErrorString(int code);
522
523#ifdef __cplusplus
524}
525#endif
526
527#endif /* not XmlParse_INCLUDED */