1 //----------------------------------------------------------------------------
2 // Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
3 //                                and Clark Cooper
4 // Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.
5 //
6 // Expat - Version 2.0.0 Release Milano 0.83 (PasExpat 2.0.0 RM0.83)
7 // Pascal Port By: Milan Marusinec alias Milano
8 //                 milan@marusinec.sk
9 //                 http://www.pasports.org/pasexpat
10 // Copyright (c) 2006
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 // [Pascal Port History] -----------------------------------------------------
32 //
33 // 01.05.2006-Milano: Unit port establishment
34 // 07.06.2006-Milano: porting
35 //
36 { expat.pas }
37 unit
38  expat ;
39 
40 INTERFACE
41 
42 uses
43  expat_basics ,
44  xmltok ,
45  xmlrole ;
46 
47 {$I expat_mode.inc }
48 
49 { TYPES DEFINITION }
50 type
51 {$I expat_external.inc }
52 
53  XML_Parser = ^XML_ParserStruct;
54 
55  XML_Bool = int8u;
56 
57 { The XML_Status enum gives the possible return values for several API functions. }
58  XML_Status = (XML_STATUS_ERROR ,XML_STATUS_OK ,XML_STATUS_SUSPENDED );
59 
60  XML_Error = (
61   XML_ERROR_NONE ,
62   XML_ERROR_NO_MEMORY ,
63   XML_ERROR_SYNTAX ,
64   XML_ERROR_NO_ELEMENTS ,
65   XML_ERROR_INVALID_TOKEN ,
66   XML_ERROR_UNCLOSED_TOKEN ,
67   XML_ERROR_PARTIAL_CHAR ,
68   XML_ERROR_TAG_MISMATCH ,
69   XML_ERROR_DUPLICATE_ATTRIBUTE ,
70   XML_ERROR_JUNK_AFTER_DOC_ELEMENT ,
71   XML_ERROR_PARAM_ENTITY_REF ,
72   XML_ERROR_UNDEFINED_ENTITY ,
73   XML_ERROR_RECURSIVE_ENTITY_REF ,
74   XML_ERROR_ASYNC_ENTITY ,
75   XML_ERROR_BAD_CHAR_REF ,
76   XML_ERROR_BINARY_ENTITY_REF ,
77   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF ,
78   XML_ERROR_MISPLACED_XML_PI ,
79   XML_ERROR_UNKNOWN_ENCODING ,
80   XML_ERROR_INCORRECT_ENCODING ,
81   XML_ERROR_UNCLOSED_CDATA_SECTION ,
82   XML_ERROR_EXTERNAL_ENTITY_HANDLING ,
83   XML_ERROR_NOT_STANDALONE ,
84   XML_ERROR_UNEXPECTED_STATE ,
85   XML_ERROR_ENTITY_DECLARED_IN_PE ,
86   XML_ERROR_FEATURE_REQUIRES_XML_DTD ,
87   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING ,
88   { Added in 1.95.7. }
89   XML_ERROR_UNBOUND_PREFIX ,
90   { Added in 1.95.8. }
91   XML_ERROR_UNDECLARING_PREFIX ,
92   XML_ERROR_INCOMPLETE_PE ,
93   XML_ERROR_XML_DECL ,
94   XML_ERROR_TEXT_DECL ,
95   XML_ERROR_PUBLICID ,
96   XML_ERROR_SUSPENDED ,
97   XML_ERROR_NOT_SUSPENDED ,
98   XML_ERROR_ABORTED ,
99   XML_ERROR_FINISHED ,
100   XML_ERROR_SUSPEND_PE ,
101   { Added in 2.0. }
102   XML_ERROR_RESERVED_PREFIX_XML ,
103   XML_ERROR_RESERVED_PREFIX_XMLNS ,
104   XML_ERROR_RESERVED_NAMESPACE_URI );
105 
106  XML_Content_Type = (
107   ___SKIP_ZERO____  ,
108   XML_CTYPE_EMPTY ,
109   XML_CTYPE_ANY ,
110   XML_CTYPE_MIXED ,
111   XML_CTYPE_NAME ,
112   XML_CTYPE_CHOICE ,
113   XML_CTYPE_SEQ );
114 
115  XML_Content_Quant = (
116   XML_CQUANT_NONE ,
117   XML_CQUANT_OPT ,
118   XML_CQUANT_REP ,
119   XML_CQUANT_PLUS );
120 
121  XML_ParamEntityParsing = (
122   XML_PARAM_ENTITY_PARSING_NEVER ,
123   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE ,
124   XML_PARAM_ENTITY_PARSING_ALWAYS );
125 
126 { If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
127   XML_CQUANT_NONE, and the other fields will be zero or NULL.
128   If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
129   numchildren will contain number of elements that may be mixed in
130   and children point to an array of XML_Content cells that will be
131   all of XML_CTYPE_NAME type with no quantification.
132 
133   If type == XML_CTYPE_NAME, then the name points to the name, and
134   the numchildren field will be zero and children will be NULL. The
135   quant fields indicates any quantifiers placed on the name.
136 
137   CHOICE and SEQ will have name NULL, the number of children in
138   numchildren and children will point, recursively, to an array
139   of XML_Content cells.
140 
141   The EMPTY, ANY, and MIXED types will only occur at top level. }
142  XML_Content_ptr = ^XML_Content;
143 
144  XML_cp = record
145    type_ : XML_Content_Type;
146    quant : XML_Content_Quant;
147    name  : XML_Char_ptr;
148 
149    numchildren : unsigned;
150    children    : XML_Content_ptr;
151 
152   end;
153 
154  XML_Content = XML_cp;
155 
156 { This is called for an element declaration. See above for
157   description of the model argument. It's the caller's responsibility
158   to free model when finished with it. }
159  XML_ElementDeclHandler = procedure(userData : pointer; name : XML_Char_ptr; model : XML_Content_ptr );
160 
161 { The Attlist declaration handler is called for *each* attribute. So
162   a single Attlist declaration with multiple attributes declared will
163   generate multiple calls to this handler. The "default" parameter
164   may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
165   keyword. The "isrequired" parameter will be true and the default
166   value will be NULL in the case of "#REQUIRED". If "isrequired" is
167   true and default is non-NULL, then this is a "#FIXED" default. }
168  XML_AttlistDeclHandler = procedure(
169                            userData : pointer;
170                            elname ,attname ,att_type ,dflt : XML_Char_ptr;
171                            isrequired : int );
172 
173 { The XML declaration handler is called for *both* XML declarations
174   and text declarations. The way to distinguish is that the version
175   parameter will be NULL for text declarations. The encoding
176   parameter may be NULL for XML declarations. The standalone
177   parameter will be -1, 0, or 1 indicating respectively that there
178   was no standalone parameter in the declaration, that it was given
179   as no, or that it was given as yes. }
180  XML_XmlDeclHandler = procedure(userData : pointer; version ,encoding : XML_Char_ptr; standalone : int );
181 
182 { This is called for entity declarations. The is_parameter_entity
183   argument will be non-zero if the entity is a parameter entity, zero
184   otherwise.
185 
186   For internal entities (<!ENTITY foo "bar">), value will
187   be non-NULL and systemId, publicID, and notationName will be NULL.
188   The value string is NOT nul-terminated; the length is provided in
189   the value_length argument. Since it is legal to have zero-length
190   values, do not use this argument to test for internal entities.
191 
192   For external entities, value will be NULL and systemId will be
193   non-NULL. The publicId argument will be NULL unless a public
194   identifier was provided. The notationName argument will have a
195   non-NULL value only for unparsed entity declarations.
196 
197   Note that is_parameter_entity can't be changed to XML_Bool, since
198   that would break binary compatibility. }
199  XML_EntityDeclHandler = procedure(
200                           userData : pointer;
201                           entityName : XML_Char_ptr;
202                           is_parameter_entity : int;
203                           value : XML_Char_ptr;
204                           value_length : int;
205                           base ,systemId ,publicId ,notationName : XML_Char_ptr );
206 
207 { atts is array of name/value pairs, terminated by 0;
208   names and values are 0 terminated. }
209  XML_StartElementHandler = procedure(userData : pointer; name : XML_Char_ptr; atts : XML_Char_ptr_ptr );
210  XML_EndElementHandler   = procedure(userData : pointer; name : XML_Char_ptr );
211 
212 { s is not 0 terminated. }
213  XML_CharacterDataHandler = procedure(userData : pointer; s : XML_Char_ptr; len : int );
214 
215 { target and data are 0 terminated }
216  XML_ProcessingInstructionHandler = procedure(userData : pointer; target ,data : XML_Char_ptr );
217 
218 { data is 0 terminated }
219  XML_CommentHandler = procedure(userData : pointer; data : XML_Char_ptr );
220 
221  XML_StartCdataSectionHandler = procedure(userData : pointer );
222  XML_EndCdataSectionHandler   = procedure(userData : pointer );
223 
224 
225 { This is called for any characters in the XML document for which
226   there is no applicable handler.  This includes both characters that
227   are part of markup which is of a kind that is not reported
228   (comments, markup declarations), or characters that are part of a
229   construct which could be reported but for which no handler has been
230   supplied. The characters are passed exactly as they were in the XML
231   document except that they will be encoded in UTF-8 or UTF-16.
232   Line boundaries are not normalized. Note that a byte order mark
233   character is not passed to the default handler. There are no
234   guarantees about how characters are divided between calls to the
235   default handler: for example, a comment might be split between
236   multiple calls. }
237  XML_DefaultHandler = procedure(userData : pointer; s : XML_Char_ptr; len : int );
238 
239 { This is called for the start of the DOCTYPE declaration, before
240   any DTD or internal subset is parsed. }
241  XML_StartDoctypeDeclHandler = procedure(
242                                 userData : pointer;
243                                 doctypeName ,sysid ,pubid : XML_Char_ptr;
244                                 has_internal_subset : int );
245 
246 { This is called for the start of the DOCTYPE declaration when the
247   closing > is encountered, but after processing any external
248   subset. }
249  XML_EndDoctypeDeclHandler = procedure(userData : pointer );
250 
251 { OBSOLETE -- OBSOLETE -- OBSOLETE
252   This handler has been superceded by the EntityDeclHandler above.
253   It is provided here for backward compatibility.
254 
255   This is called for a declaration of an unparsed (NDATA) entity.
256   The base argument is whatever was set by XML_SetBase. The
257   entityName, systemId and notationName arguments will never be
258   NULL. The other arguments may be. }
259  XML_UnparsedEntityDeclHandler = procedure(
260                                   userData : pointer;
261                                   entityName ,base ,systemId ,publicId ,notationName : XML_Char_ptr );
262 
263 { This is called for a declaration of notation.  The base argument is
264   whatever was set by XML_SetBase. The notationName will never be
265   NULL.  The other arguments can be. }
266  XML_NotationDeclHandler = procedure(
267                             userData : pointer;
268                             notationName ,base ,systemId ,publicId : XML_Char_ptr );
269 
270 { When namespace processing is enabled, these are called once for
271   each namespace declaration. The call to the start and end element
272   handlers occur between the calls to the start and end namespace
273   declaration handlers. For an xmlns attribute, prefix will be
274   NULL.  For an xmlns="" attribute, uri will be NULL. }
275  XML_StartNamespaceDeclHandler = procedure(userData : pointer; prefix ,uri : XML_Char_ptr );
276  XML_EndNamespaceDeclHandler   = procedure(userData : pointer; prefix : XML_Char_ptr );
277 
278 { This is called if the document is not standalone, that is, it has an
279   external subset or a reference to a parameter entity, but does not
280   have standalone="yes". If this handler returns XML_STATUS_ERROR,
281   then processing will not continue, and the parser will return a
282   XML_ERROR_NOT_STANDALONE error.
283   If parameter entity parsing is enabled, then in addition to the
284   conditions above this handler will only be called if the referenced
285   entity was actually read. }
serDatanull286  XML_NotStandaloneHandler = function(userData : pointer ) : int;
287 
288 { This is called for a reference to an external parsed general
289   entity.  The referenced entity is not automatically parsed.  The
290   application can parse it immediately or later using
291   XML_ExternalEntityParserCreate.
292 
293   The parser argument is the parser parsing the entity containing the
294   reference; it can be passed as the parser argument to
295   XML_ExternalEntityParserCreate.  The systemId argument is the
296   system identifier as specified in the entity declaration; it will
297   not be NULL.
298 
299   The base argument is the system identifier that should be used as
300   the base for resolving systemId if systemId was relative; this is
301   set by XML_SetBase; it may be NULL.
302 
303   The publicId argument is the public identifier as specified in the
304   entity declaration, or NULL if none was specified; the whitespace
305   in the public identifier will have been normalized as required by
306   the XML spec.
307 
308   The context argument specifies the parsing context in the format
309   expected by the context argument to XML_ExternalEntityParserCreate;
310   context is valid only until the handler returns, so if the
311   referenced entity is to be parsed later, it must be copied.
312   context is NULL only when the entity is a parameter entity.
313 
314   The handler should return XML_STATUS_ERROR if processing should not
315   continue because of a fatal error in the handling of the external
316   entity.  In this case the calling parser will return an
317   XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
318 
319   Note that unlike other handlers the first argument is the parser,
320   not userData. }
321  XML_ExternalEntityRefHandler = function(
parsernull322                                  parser : XML_Parser;
323                                  context ,base ,systemId ,publicId : XML_Char_ptr ) : int;
324 
325 { This is called in two situations:
326   1) An entity reference is encountered for which no declaration
327      has been read *and* this is not an error.
328   2) An internal entity reference is read, but not expanded, because
329      XML_SetDefaultHandler has been called.
330   Note: skipped parameter entities in declarations and skipped general
331         entities in attribute values cannot be reported, because
332         the event would be out of sync with the reporting of the
333         declarations or attribute values }
334  XML_SkippedEntityHandler = procedure(userData : pointer; entityName : XML_Char_ptr; is_parameter_entity : int );
335 
336 (* This structure is filled in by the XML_UnknownEncodingHandler to
337   provide information to the parser about encodings that are unknown
338   to the parser.
339 
340   The map[b] member gives information about byte sequences whose
341   first byte is b.
342 
343   If map[b] is c where c is >= 0, then b by itself encodes the
344   Unicode scalar value c.
345 
346   If map[b] is -1, then the byte sequence is malformed.
347 
348   If map[b] is -n, where n >= 2, then b is the first byte of an
349   n-byte sequence that encodes a single Unicode scalar value.
350 
351   The data member will be passed as the first argument to the convert
352   function.
353 
354   The convert function is used to convert multibyte sequences; s will
355   point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
356   convert function must return the Unicode scalar value represented
357   by this byte sequence or -1 if the byte sequence is malformed.
358 
359   The convert function may be NULL if the encoding is a single-byte
360   encoding, that is if map[b] >= -1 for all bytes b.
361 
362   When the parser is finished with the encoding, then if release is
363   not NULL, it will call release passing it the data member; once
364   release has been called, the convert function will not be called
365   again.
366 
367   Expat places certain restrictions on the encodings that are supported
368   using this mechanism.
369 
370   1. Every ASCII character that can appear in a well-formed XML document,
371      other than the characters
372 
373      $@\^`{}~
374 
375      must be represented by a single byte, and that byte must be the
376      same byte that represents that character in ASCII.
377 
378   2. No character may require more than 4 bytes to encode.
379 
380   3. All characters encoded must have Unicode scalar values <=
381      0xFFFF, (i.e., characters that would be encoded by surrogates in
382      UTF-16 are  not allowed).  Note that this restriction doesn't
383      apply to the built-in support for UTF-8 and UTF-16.
384 
385   4. No Unicode character may be encoded by more than one distinct
386      sequence of bytes. *)
387  XML_Encoding_ptr = ^XML_Encoding;
388  XML_Encoding = record
389    map  : array[0..255 ] of int;
390    data : pointer;
391 
392    convert : function (data : pointer; s : char_ptr ) : int;
393    release : procedure(data : pointer );
394 
395   end;
396 
397 { This is called for an encoding that is unknown to the parser.
398 
399   The encodingHandlerData argument is that which was passed as the
400   second argument to XML_SetUnknownEncodingHandler.
401 
402   The name argument gives the name of the encoding as specified in
403   the encoding declaration.
404 
405   If the callback can provide information about the encoding, it must
406   fill in the XML_Encoding structure, and return XML_STATUS_OK.
407   Otherwise it must return XML_STATUS_ERROR.
408 
409   If info does not describe a suitable encoding, then the parser will
410   return an XML_UNKNOWN_ENCODING error. }
411  XML_UnknownEncodingHandler = function(
encodingHandlerDatanull412                                encodingHandlerData : pointer;
413                                name : XML_Char_ptr;
414                                info : XML_Encoding_ptr ) : int;
415 
416 
417  XML_Memory_Handling_Suite_ptr = ^XML_Memory_Handling_Suite;
418  XML_Memory_Handling_Suite = record
arnull419    malloc_fcn  : function(var ptr : pointer; sz : integer ) : boolean;
arnull420    realloc_fcn : function(var ptr : pointer; old ,sz : integer ) : boolean;
arnull421    free_fcn    : function(var ptr : pointer; sz : integer ) : boolean;
422 
423   end;
424 
425  KEY = XML_Char_ptr;
426 
427  NAMED_ptr_ptr = ^NAMED_ptr;
428  NAMED_ptr = ^NAMED;
429  NAMED = record
430    name  : KEY;
431    alloc : int;
432 
433   end;
434 
435  HASH_TABLE_ptr = ^HASH_TABLE;
436  HASH_TABLE = record
437    v : NAMED_ptr_ptr;
438    a : int;
439 
440    power : int8u;
441    size  ,
442    used  : size_t;
443    mem   : XML_Memory_Handling_Suite_ptr;
444 
445   end;
446 
447  ENTITY_ptr = ^ENTITY;
448  ENTITY = record
449    name  : XML_Char_ptr;
450    alloc : int;
451 
452    textPtr   : XML_Char_ptr;
453    textLen   ,                { length in XML_Chars }
454    processed : int;           { # of processed bytes - when suspended }
455    systemId  ,
456    base      ,
457    publicId  ,
458    notation  : XML_Char_ptr;
459 
460    open        ,
461    is_param    ,
462    is_internal : XML_Bool;    { true if declared in internal subset outside PE }
463 
464   end;
465 
466  OPEN_INTERNAL_ENTITY_ptr = ^OPEN_INTERNAL_ENTITY;
467  OPEN_INTERNAL_ENTITY = record
468    internalEventPtr    ,
469    internalEventEndPtr : char_ptr;
470 
471    next   : OPEN_INTERNAL_ENTITY_ptr;
472    entity : ENTITY_ptr;
473 
474    startTagLevel : int;
475    betweenDecl   : XML_Bool; { WFC: PE Between Declarations }
476 
477   end;
478 
479  CONTENT_SCAFFOLD_ptr = ^CONTENT_SCAFFOLD;
480  CONTENT_SCAFFOLD = record
481    type_ : XML_Content_Type;
482    quant : XML_Content_Quant;
483    name  : XML_Char_ptr;
484 
485    firstchild ,
486    lastchild  ,
487    childcnt   ,
488    nextsib    : int;
489 
490   end;
491 
492  PREFIX_ptr = ^PREFIX;
493 
494  ATTRIBUTE_ID_ptr = ^ATTRIBUTE_ID;
495  ATTRIBUTE_ID = record
496    name   : XML_Char_ptr;
497    alloc  : int;
498    prefix : PREFIX_ptr;
499 
500    maybeTokenized ,
501    xmlns          : XML_Bool;
502 
503   end;
504 
505  DEFAULT_ATTRIBUTE_ptr = ^DEFAULT_ATTRIBUTE;
506  DEFAULT_ATTRIBUTE = record
507    id : ATTRIBUTE_ID_ptr;
508 
509    isCdata : XML_Bool;
510    value   : XML_Char_ptr;
511 
512   end;
513 
514  ELEMENT_TYPE_ptr = ^ELEMENT_TYPE;
515  ELEMENT_TYPE = record
516    name   : XML_Char_ptr;
517    alloc  : int;
518    prefix : PREFIX_ptr;
519    idAtt  : ATTRIBUTE_ID_ptr;
520 
521    nDefaultAtts     ,
522    allocDefaultAtts ,
523    defaultAttsAlloc : int;
524 
525    defaultAtts : DEFAULT_ATTRIBUTE_ptr;
526 
527   end;
528 
529  TAG_NAME_ptr = ^TAG_NAME;
530  TAG_NAME = record
531    str       ,
532    localPart ,
533    prefix    : XML_Char_ptr;
534    strLen    ,
535    uriLen    ,
536    prefixLen : int;
537 
538   end;
539 
540 { TAG represents an open element.
541   The name of the element is stored in both the document and API
542   encodings.  The memory buffer 'buf' is a separately-allocated
543   memory area which stores the name.  During the XML_Parse()/
544   XMLParseBuffer() when the element is open, the memory for the 'raw'
545   version of the name (in the document encoding) is shared with the
546   document buffer.  If the element is open across calls to
547   XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to
548   contain the 'raw' name as well.
549 
550   A parser re-uses these structures, maintaining a list of allocated
551   TAG objects in a free list. }
552  BINDING_ptr_ptr = ^BINDING_ptr;
553  BINDING_ptr = ^BINDING;
554 
555  TAG_ptr = ^TAG;
556  TAG = record
557    parent  : TAG_ptr;      { parent of this element }
558    rawName : char_ptr;     { tagName in the original encoding }
559 
560    rawNameLength : int;
561 
562    name : TAG_NAME;        { tagName in the API encoding }
563 
564    buf    ,                { buffer for name components }
565    bufEnd : char_ptr;      { end of the buffer }
566    alloc  : int;
567 
568    bindings : BINDING_ptr;
569 
570   end;
571 
572  BINDING = record
573    prefix : PREFIX_ptr;
574 
575    nextTagBinding    ,
576    prevPrefixBinding : BINDING_ptr;
577 
578    attId : ATTRIBUTE_ID_ptr;
579    uri   : XML_Char_ptr;
580 
581    uriLen   ,
582    uriAlloc : int;
583 
584   end;
585 
586  PREFIX = record
587    name    : XML_Char_ptr;
588    alloc   : int;
589    binding : BINDING_ptr;
590 
591   end;
592 
593  NS_ATT_ptr = ^NS_ATT;
594  NS_ATT = record
595    version ,
596    hash    : int32u;
597    uriName : XML_Char_ptr;
598 
599   end;
600 
601  BLOCK_ptr = ^BLOCK;
602  BLOCK = record
603    next  : BLOCK_ptr;
604    size  ,
605    alloc : int;
606 
607    s : array[0..0 ] of XML_Char;
608 
609   end;
610 
611  STRING_POOL_ptr = ^STRING_POOL;
612  STRING_POOL = record
613    blocks     ,
614    freeBlocks : BLOCK_ptr;
615 
616    end_  ,
617    ptr   ,
618    start : XML_Char_ptr;
619 
620    mem : XML_Memory_Handling_Suite_ptr;
621 
622   end;
623 
624  DTD_ptr = ^DTD;
625  DTD = record
626    generalEntities ,
627    elementTypes    ,
628    attributeIds    ,
629    prefixes        : HASH_TABLE;
630 
631    pool            ,
632    entityValuePool : STRING_POOL;
633 
634   { false once a parameter entity reference has been skipped }
635    keepProcessing : XML_Bool;
636 
637   { true once an internal or external PE reference has been encountered;
638     this includes the reference to an external subset }
639    hasParamEntityRefs ,
640    standalone         : XML_Bool;
641 
642   {$IFDEF XML_DTD }
643   { indicates if external PE has been read }
644    paramEntityRead : XML_Bool;
645    paramEntities   : HASH_TABLE;
646 
647   {$ENDIF }
648 
649    defaultPrefix : PREFIX;
650 
651   { === scaffolding for building content model === }
652    in_eldecl : XML_Bool;
653    scaffold  : CONTENT_SCAFFOLD_ptr;
654 
655    contentStringLen ,
656    scaffSize        ,
657    scaffCount       : unsigned;
658 
659    scaffLevel : int;
660    scaffIndex : int_ptr;
661    scaffAlloc : int;
662 
663   end;
664 
665  XML_Parsing = (
666   XML_INITIALIZED ,
667   XML_PARSING_    ,
668   XML_FINISHED    ,
669   XML_SUSPENDED   );
670 
671  XML_ParsingStatus = record
672    parsing     : XML_Parsing;
673    finalBuffer : XML_Bool;
674 
675   end;
676 
arsernull677  Processor = function(parser : XML_Parser; start ,end_ : char_ptr; endPtr : char_ptr_ptr ) : XML_Error;
678 
679  XML_ParserStruct = record
680    m_userData   ,
681    m_handlerArg : pointer;
682 
683    m_buffer : char_ptr;
684    m_mem    : XML_Memory_Handling_Suite;
685 
686   { first character to be parsed }
687    m_bufferPtr : char_ptr;
688 
689   { past last character to be parsed }
690    m_bufferEnd : char_ptr;
691 
692   { allocated end of buffer }
693    m_bufferLim : char_ptr;
694 
695   { the size of the allocated buffer }
696    m_bufferAloc : int;
697 
698    m_parseEndByteIndex : XML_Index;
699 
700    m_parseEndPtr : char_ptr;
701    m_dataBuf     ,
702    m_dataBufEnd  : XML_Char_ptr;
703 
704   { XML Handlers }
705    m_startElementHandler          : XML_StartElementHandler;
706    m_endElementHandler            : XML_EndElementHandler;
707    m_characterDataHandler         : XML_CharacterDataHandler;
708    m_processingInstructionHandler : XML_ProcessingInstructionHandler;
709    m_commentHandler               : XML_CommentHandler;
710    m_startCdataSectionHandler     : XML_StartCdataSectionHandler;
711    m_endCdataSectionHandler       : XML_EndCdataSectionHandler;
712    m_defaultHandler               : XML_DefaultHandler;
713    m_startDoctypeDeclHandler      : XML_StartDoctypeDeclHandler;
714    m_endDoctypeDeclHandler        : XML_EndDoctypeDeclHandler;
715    m_unparsedEntityDeclHandler    : XML_UnparsedEntityDeclHandler;
716    m_notationDeclHandler          : XML_NotationDeclHandler;
717    m_startNamespaceDeclHandler    : XML_StartNamespaceDeclHandler;
718    m_endNamespaceDeclHandler      : XML_EndNamespaceDeclHandler;
719    m_notStandaloneHandler         : XML_NotStandaloneHandler;
720    m_externalEntityRefHandler     : XML_ExternalEntityRefHandler;
721    m_externalEntityRefHandlerArg  : XML_Parser;
722    m_skippedEntityHandler         : XML_SkippedEntityHandler;
723    m_unknownEncodingHandler       : XML_UnknownEncodingHandler;
724    m_elementDeclHandler           : XML_ElementDeclHandler;
725    m_attlistDeclHandler           : XML_AttlistDeclHandler;
726    m_entityDeclHandler            : XML_EntityDeclHandler;
727    m_xmlDeclHandler               : XML_XmlDeclHandler;
728 
729    m_encoding             : ENCODING_ptr;
730    m_initEncoding         : INIT_ENCODING;
731    m_internalEncoding     : ENCODING_ptr;
732    m_protocolEncodingName : XML_Char_ptr;
733 
734    m_ns          ,
735    m_ns_triplets : XML_Bool;
736 
737    m_unknownEncodingMem         ,
738    m_unknownEncodingData        ,
739    m_unknownEncodingHandlerData : pointer;
740    m_unknownEncodingAlloc       : int;
741 
742    m_unknownEncodingRelease : procedure(void : pointer );
743 
744    m_prologState : PROLOG_STATE;
745    m_processor   : Processor;
746    m_errorCode   : XML_Error;
747    m_eventPtr    ,
748    m_eventEndPtr ,
749    m_positionPtr : char_ptr;
750 
751    m_openInternalEntities ,
752    m_freeInternalEntities : OPEN_INTERNAL_ENTITY_ptr;
753 
754    m_defaultExpandInternalEntities : XML_Bool;
755 
756    m_tagLevel   : int;
757    m_declEntity : ENTITY_ptr;
758 
759    m_doctypeName          ,
760    m_doctypeSysid         ,
761    m_doctypePubid         ,
762    m_declAttributeType    ,
763    m_declNotationName     ,
764    m_declNotationPublicId : XML_Char_ptr;
765 
766    m_declElementType : ELEMENT_TYPE_ptr;
767    m_declAttributeId : ATTRIBUTE_ID_ptr;
768 
769    m_declAttributeIsCdata ,
770    m_declAttributeIsId    : XML_Bool;
771 
772    m_dtd : DTD_ptr;
773 
774    m_curBase : XML_Char_ptr;
775 
776    m_tagStack    ,
777    m_freeTagList : TAG_ptr;
778 
779    m_inheritedBindings ,
780    m_freeBindingList   : BINDING_ptr;
781 
782    m_attsSize       ,
783    m_attsAlloc      ,
784    m_nsAttsAlloc    ,
785    m_nSpecifiedAtts ,
786    m_idAttIndex     : int;
787 
788    m_atts   : ATTRIBUTE_ptr;
789    m_nsAtts : NS_ATT_ptr;
790 
791    m_nsAttsVersion : unsigned;
792    m_nsAttsPower   : int8u;
793 
794    m_position  : POSITION;
795    m_tempPool  ,
796    m_temp2Pool : STRING_POOL;
797 
798    m_groupConnector : char_ptr;
799    m_groupSize      ,
800    m_groupAlloc     : unsigned;
801 
802    m_namespaceSeparator : XML_Char;
803 
804    m_parentParser  : XML_Parser;
805    m_parsingStatus : XML_ParsingStatus;
806 
807   {$IFDEF XML_DTD }
808    m_isParamEntity ,
809    m_useForeignDTD : XML_Bool;
810 
811    m_paramEntityParsing : XML_ParamEntityParsing;
812 
813   {$ENDIF }
814 
815   end;
816 
817 { GLOBAL CONSTANTS }
818 const
819  XML_TRUE  = 1;
820  XML_FALSE = 0;
821 
822 
823 { GLOBAL PROCEDURES }
824 { Constructs a new parser; encoding is the encoding specified by the
825   external protocol or NIL if there is none specified. }
XML_ParserCreatenull826  function  XML_ParserCreate(const encoding : XML_Char_ptr ) : XML_Parser;
827 
828 { Constructs a new parser using the memory management suite referred to
829   by memsuite. If memsuite is NULL, then use the standard library memory
830   suite. If namespaceSeparator is non-NULL it creates a parser with
831   namespace processing as described above. The character pointed at
832   will serve as the namespace separator.
833 
834   All further memory operations used for the created parser will come from
835   the given suite. }
XML_ParserCreate_MMnull836  function  XML_ParserCreate_MM(
837             encoding : XML_Char_ptr;
838             memsuite : XML_Memory_Handling_Suite_ptr;
839             namespaceSeparator : XML_Char_ptr ) : XML_Parser;
840 
841 { This value is passed as the userData argument to callbacks. }
842  procedure XML_SetUserData(parser : XML_Parser; userData : pointer );
843 
844  procedure XML_SetElementHandler(
845             parser : XML_Parser;
846             start  : XML_StartElementHandler;
847             end_   : XML_EndElementHandler );
848 
849  procedure XML_SetCharacterDataHandler(
850             parser  : XML_Parser;
851             handler : XML_CharacterDataHandler );
852 
853 { Parses some input. Returns XML_STATUS_ERROR if a fatal error is
854   detected.  The last call to XML_Parse must have isFinal true; len
855   may be zero for this call (or any other).
856 
857   Though the return values for these functions has always been
858   described as a Boolean value, the implementation, at least for the
859   1.95.x series, has always returned exactly one of the XML_Status
860   values. }
XML_Parsenull861  function  XML_Parse(parser : XML_Parser; const s : char_ptr; len ,isFinal : int ) : XML_Status;
862 
863 { If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
864   XML_GetErrorCode returns information about the error. }
XML_GetErrorCodenull865  function  XML_GetErrorCode(parser : XML_Parser ) : XML_Error;
866 
867 { Returns a string describing the error. }
XML_ErrorStringnull868  function  XML_ErrorString(code : XML_Error ) : XML_LChar_ptr;
869 
870 { These functions return information about the current parse
871   location.  They may be called from any callback called to report
872   some parse event; in this case the location is the location of the
873   first of the sequence of characters that generated the event.  When
874   called from callbacks generated by declarations in the document
875   prologue, the location identified isn't as neatly defined, but will
876   be within the relevant markup.  When called outside of the callback
877   functions, the position indicated will be just past the last parse
878   event (regardless of whether there was an associated callback).
879 
880   They may also be called after returning from a call to XML_Parse
881   or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
882   the location is the location of the character at which the error
883   was detected; otherwise the location is the location of the last
884   parse event, as described above. }
XML_GetCurrentLineNumbernull885  function  XML_GetCurrentLineNumber(parser : XML_Parser ) : XML_Size;
886 
887 { Frees memory used by the parser. }
888  procedure XML_ParserFree(parser : XML_Parser );
889 
890 
891 IMPLEMENTATION
892 { LOCAL VARIABLES & CONSTANTS }
893 { UNIT IMPLEMENTATION }
894 {$I xmlparse.inc }
895 
896 END.
897 
898 
899