summaryrefslogtreecommitdiff
path: root/packages/libxml/src/parser.inc
blob: f872a86c6d37ed66d42189f28825073efa02df99 (plain)
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
(*
 * Summary: the core parser module
 * Description: Interfaces, constants and types related to the XML parser
 *
 * Copy: See Copyright for the status of this software.
 *
 * Author: Daniel Veillard
 *)

{$IFDEF POINTER}
  xmlParserInputPtr = ^xmlParserInput;
  xmlParserInputPtrPtr = ^xmlParserInputPtr;
  xmlParserNodeInfoPtr = ^xmlParserNodeInfo;
  xmlParserNodeInfoSeqPtr = ^xmlParserNodeInfoSeq;
  xmlParserCtxtPtr = ^xmlParserCtxt;
  xmlSAXLocatorPtr = ^xmlSAXLocator;
  xmlSAXHandlerPtr = ^xmlSAXHandler;
  xmlSAXHandlerV1Ptr = ^xmlSAXHandlerV1;
{$ENDIF}

{$IFDEF CONST}
(**
 * XML_DEFAULT_VERSION:
 *
 * The default version of XML used: 1.0
 *)
  XML_DEFAULT_VERSION = '1.0';
{$ENDIF}

{$IFDEF TYPE}
(**
 * xmlParserInput:
 *
 * An xmlParserInput is an input flow for the XML processor.
 * Each entity parsed is associated an xmlParserInput (except the
 * few predefined ones). This is the case both for internal entities
 * - in which case the flow is already completely in memory - or
 * external entities - in which case we use the buf structure for
 * progressive reading and I18N conversions to the internal UTF-8 format.
 *)

(**
 * xmlParserInputDeallocate:
 * @str:  the string to deallocate
 *
 * Callback for freeing some parser input allocations.
 *)
  xmlParserInputDeallocate = procedure(str: xmlCharPtr); EXTDECL;

  xmlParserInput = record
    (* Input buffer *)
    buf         : xmlParserInputBufferPtr;      (* UTF-8 encoded buffer *)

    filename    : pchar;             (* The file analyzed, if any *)
    directory   : pchar;            (* the directory/base of the file *)
    base        : xmlCharPtr;              (* Base of the array to parse *)
    cur         : xmlCharPtr;               (* Current char being parsed *)
    _end        : xmlCharPtr;               (* end of the array to parse *)
    length      : cint;                       (* length if known *)
    line        : cint;                         (* Current line *)
    col         : cint;                          (* Current column *)
    (*
     * NOTE: consumed is only tested for equality in the parser code,
     *       so even if there is an overflow this should not give troubles
     *       for parsing very large instances.
     *)
    consumed    : culong;           (* How many xmlChars already consumed *)
    free        : xmlParserInputDeallocate;    (* function to deallocate the base *)
    encoding    : xmlCharPtr;          (* the encoding string for entity *)
    version     : xmlCharPtr;           (* the version string for entity *)
    standalone  : cint;                   (* Was that entity marked standalone *)
    id          : cint;                           (* an unique identifier for the entity *)
  end;

(**
 * xmlParserNodeInfo:
 *
 * The parser can be asked to collect Node informations, i.e. at what
 * place in the file they were detected.
 * NOTE: This is off by default and not very well tested.
 *)
  xmlParserNodeInfo = record
    node        : xmlNodePtr;
  (* Position & line # that text that created the node begins & ends on *)
    begin_pos   : culong;
    begin_line  : culong;
    end_pos     : culong;
    end_line    : culong;
  end;

  xmlParserNodeInfoSeq = record
    maximum     : culong;
    length      : culong;
    buffer      : xmlParserNodeInfoPtr;
  end;

(**
 * xmlParserInputState:
 *
 * The parser is now working also as a state based parser.
 * The recursive one use the state info for entities processing.
 *)
  xmlParserInputState = (
    XML_PARSER_EOF = -1,	(* nothing is to be parsed *)
    XML_PARSER_START = 0,	(* nothing has been parsed *)
    XML_PARSER_MISC,		(* Misc* before int subset *)
    XML_PARSER_PI,		(* Within a processing instruction *)
    XML_PARSER_DTD,		(* within some DTD content *)
    XML_PARSER_PROLOG,		(* Misc* after internal subset *)
    XML_PARSER_COMMENT,		(* within a comment *)
    XML_PARSER_START_TAG,	(* within a start tag *)
    XML_PARSER_CONTENT,		(* within the content *)
    XML_PARSER_CDATA_SECTION,	(* within a CDATA section *)
    XML_PARSER_END_TAG,		(* within a closing tag *)
    XML_PARSER_ENTITY_DECL,	(* within an entity declaration *)
    XML_PARSER_ENTITY_VALUE,	(* within an entity value in a decl *)
    XML_PARSER_ATTRIBUTE_VALUE,	(* within an attribute value *)
    XML_PARSER_SYSTEM_LITERAL,	(* within a SYSTEM value *)
    XML_PARSER_EPILOG, 		(* the Misc* after the last end tag *)
    XML_PARSER_IGNORE,		(* within an IGNORED section *)
    XML_PARSER_PUBLIC_LITERAL 	(* within a PUBLIC value *)
  );
{$ENDIF}

{$IFDEF CONST}
(**
 * XML_DETECT_IDS:
 *
 * Bit in the loadsubset context field to tell to do ID/REFs lookups.
 * Use it to initialize xmlLoadExtDtdDefaultValue.
 *)
  XML_DETECT_IDS = 2;

(**
 * XML_COMPLETE_ATTRS:
 *
 * Bit in the loadsubset context field to tell to do complete the
 * elements attributes lists with the ones defaulted from the DTDs.
 * Use it to initialize xmlLoadExtDtdDefaultValue.
 *)
  XML_COMPLETE_ATTRS = 4;

(**
 * XML_SKIP_IDS:
 *
 * Bit in the loadsubset context field to tell to not do ID/REFs registration.
 * Used to initialize xmlLoadExtDtdDefaultValue in some special cases.
 *)
  XML_SKIP_IDS = 8;
{$ENDIF}

{$IFDEF TYPE}
(**
 * xmlParserMode:
 *
 * A parser can operate in various modes
 *)
  xmlParserMode = (
    XML_PARSE_UNKNOWN = 0,
    XML_PARSE_DOM = 1,
    XML_PARSE_SAX = 2,
    XML_PARSE_PUSH_DOM = 3,
    XML_PARSE_PUSH_SAX = 4,
    XML_PARSE_READER = 5
  );

(**
 * xmlParserCtxt:
 *
 * The parser context.
 * NOTE This doesn't completely define the parser state, the (current ?)
 *      design of the parser uses recursive function calls since this allow
 *      and easy mapping from the production rules of the specification
 *      to the actual code. The drawback is that the actual function call
 *      also reflect the parser state. However most of the parsing routines
 *      takes as the only argument the parser context pointer, so migrating
 *      to a state based parser for progressive parsing shouldn't be too hard.
 *)
  xmlParserCtxt = record
    sax               : xmlSAXHandlerPtr;       (* The SAX handler *)
    userData          : pointer;        (* For SAX interface only, used by DOM build *)
    myDoc             : xmlDocPtr;        (* the document being built *)
    wellFormed        : cint;        (* is the document well formed *)
    replaceEntities   : cint;        (* shall we replace entities ? *)
    version           : xmlCharPtr;        (* the XML version string *)
    encoding          : xmlCharPtr;        (* the declared encoding, if any *)
    standalone        : cint;        (* standalone document *)
    html              : cint;        (* an HTML(1)/Docbook(2) document *)

    (* Input stream stack *)
    input             : xmlParserInputPtr;         (* Current input stream *)
    inputNr           : cint;       (* Number of current input streams *)
    inputMax          : cint;      (* Max number of input streams *)
    inputTab          : xmlParserInputPtrPtr;      (* stack of inputs *)

    (* Node analysis stack only used for DOM building *)
    node              : xmlNodePtr;          (* Current parsed Node *)
    nodeNr            : cint;        (* Depth of the parsing stack *)
    nodeMax           : cint;       (* Max depth of the parsing stack *)
    nodeTab           : xmlNodePtrPtr;       (* array of nodes *)

    record_info       : cint;                  (* Whether node info should be kept *)
    node_seq          : xmlParserNodeInfoSeq;    (* info about each node parsed *)

    errNo             : cint;                        (* error code *)

    hasExternalSubset : cint;        (* reference and external subset *)
    hasPErefs         : cint;        (* the internal subset has PE refs *)
    external          : cint;        (* are we parsing an external entity *)

    valid             : cint;        (* is the document valid *)
    validate          : cint;        (* shall we try to validate ? *)
    vctxt             : xmlValidCtxt;        (* The validity context *)

    instate           : xmlParserInputState;      (* current type of input *)
    token             : cint;        (* next char look-ahead *)

    directory         : pchar;        (* the data directory *)

    (* Node name stack *)
    name              : xmlCharPtr;          (* Current parsed Node *)
    nameNr            : cint;        (* Depth of the parsing stack *)
    nameMax           : cint;       (* Max depth of the parsing stack *)
    nameTab           : xmlCharPtrPtr;       (* array of nodes *)

    nbChars           : culong;       (* number of xmlChar processed *)
    checkIndex        : culong;       (* used by progressive parsing lookup *)
    keepBlanks        : cint;       (* ugly but ... *)
    disableSAX        : cint;       (* SAX callbacks are disabled *)
    inSubset          : cint;       (* Parsing is in int 1/ext 2 subset *)
    intSubName        : xmlCharPtr;    (* name of subset *)
    extSubURI         : xmlCharPtr;     (* URI of external subset *)
    extSubSystem      : xmlCharPtr;  (* SYSTEM ID of external subset *)

    (* xml:space values *)
    space             : pcint;         (* Should the parser preserve spaces *)
    spaceNr           : cint;       (* Depth of the parsing stack *)
    spaceMax          : cint;      (* Max depth of the parsing stack *)
    spaceTab          : pcint;      (* array of space infos *)

    depth             : cint;         (* to prevent entity substitution loops *)
    entity            : xmlParserInputPtr;        (* used to check entities boundaries *)
    charset           : cint;       (* encoding of the in-memory content
				         actually an xmlCharEncoding *)
    nodelen           : cint;       (* Those two fields are there to *)
    nodemem           : cint;       (* Speed up large node parsing *)
    pedantic          : cint;      (* signal pedantic warnings *)
    _private          : pointer;      (* For user data, libxml won't touch it *)

    loadsubset        : cint;    (* should the external subset be loaded *)
    linenumbers       : cint;   (* set line number in element content *)
    catalogs          : pointer;      (* document's own catalog *)
    recovery          : cint;      (* run in recovery mode *)
    progressive       : cint;   (* is this a progressive parsing *)
    dict              : xmlDictPtr;          (* dictionnary for the parser *)
    atts              : xmlCharPtrPtr;          (* array for the attributes callbacks *)
    maxatts           : cint;       (* the size of the array *)
    docdict           : cint;       (* use strings from dict to build tree *)

    (*
     * pre-interned strings
     *)
    str_xml           : xmlCharPtr;
    str_xmlns         : xmlCharPtr;
    str_xml_ns        : xmlCharPtr;

    (*
     * Everything below is used only by the new SAX mode
     *)
    sax2              : cint;          (* operating in the new SAX mode *)
    nsNr              : cint;          (* the number of inherited namespaces *)
    nsMax             : cint;         (* the size of the arrays *)
    nsTab             : xmlCharPtrPtr;         (* the array of prefix/namespace name *)
    attallocs         : pcint;     (* which attribute were allocated *)
    pushTab           : ppointer;       (* array of data for push *)
    attsDefault       : xmlHashTablePtr;   (* defaulted attributes if any *)
    attsSpecial       : xmlHashTablePtr;   (* non-CDATA attributes if any *)
    nsWellFormed      : cint;  (* is the document XML Nanespace okay *)
    options           : cint;       (* Extra options *)

    (*
     * Those fields are needed only for treaming parsing so far
     *)
    dictNames         : cint;    (* Use dictionary names for the tree *)
    freeElemsNr       : cint;  (* number of freed element nodes *)
    freeElems         : xmlNodePtr;    (* List of freed element nodes *)
    freeAttrsNr       : cint;  (* number of freed attributes nodes *)
    freeAttrs         : xmlAttrPtr;    (* List of freed attributes nodes *)

    (*
     * the complete error informations for the last error.
     *)
    lastError         : xmlError;
    parseMode         : xmlParserMode;    (* the parser mode *)
  end;

(**
 * xmlSAXLocator:
 *
 * A SAX Locator.
 *)
  getPublicIdFunc = function(ctx: pointer): xmlCharPtr; EXTDECL;
  getSystemIdFunc = function(ctx: pointer): xmlCharPtr; EXTDECL;
  getLineNumberFunc = function(ctx: pointer): cint; EXTDECL;
  getColumnNumberFunc = function(ctx: pointer): cint; EXTDECL;

  xmlSAXLocator = record
    getPublicId     : getPublicIdFunc;
    getSystemId     : getSystemIdFunc;
    getLineNumber   : getLineNumberFunc;
    getColumnNumber : getColumnNumberFunc;
  end;

(**
 * xmlSAXHandler:
 *
 * A SAX handler is bunch of callbacks called by the parser when processing
 * of the input generate data or structure informations.
 *)

(**
 * resolveEntitySAXFunc:
 * @ctx:  the user data (XML parser context)
 * @publicId: The public ID of the entity
 * @systemId: The system ID of the entity
 *
 * Callback:
 * The entity loader, to control the loading of external entities,
 * the application can either:
 *    - override this resolveEntity() callback in the SAX block
 *    - or better use the xmlSetExternalEntityLoader() function to
 *      set up it's own entity resolution routine
 *
 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
 *)
  resolveEntitySAXFunc = function(ctx: pointer; publicID, systemID: xmlCharPtr): xmlParserInputPtr; EXTDECL;

(**
 * internalSubsetSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  the root element name
 * @ExternalID:  the external ID
 * @SystemID:  the SYSTEM ID (e.g. filename or URL)
 *
 * Callback on internal subset declaration.
 *)
  internalSubsetSAXFunc = procedure(ctx: pointer; name, ExternalID, SystemID: xmlCharPtr); EXTDECL;

(**
 * externalSubsetSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  the root element name
 * @ExternalID:  the external ID
 * @SystemID:  the SYSTEM ID (e.g. filename or URL)
 *
 * Callback on external subset declaration.
 *)
  externalSubsetSAXFunc = procedure(ctx: pointer; name, ExternalID, SystemID: xmlCharPtr); EXTDECL;

(**
 * getEntitySAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name: The entity name
 *
 * Get an entity by name.
 *
 * Returns the xmlEntityPtr if found.
 *)
  getEntitySAXFunc = function(ctx: pointer; name: xmlCharPtr): xmlEntityPtr; EXTDECL;

(**
 * getParameterEntitySAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name: The entity name
 *
 * Get a parameter entity by name.
 *
 * Returns the xmlEntityPtr if found.
 *)
  getParameterEntitySAXFunc = function(ctx: pointer; name: xmlCharPtr): xmlEntityPtr; EXTDECL;

(**
 * entityDeclSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  the entity name
 * @type:  the entity type
 * @publicId: The public ID of the entity
 * @systemId: The system ID of the entity
 * @content: the entity value (without processing).
 *
 * An entity definition has been parsed.
 *)
  entityDeclSAXFunc = procedure(ctx: pointer; name: xmlCharPtr; _type: cint; publicId, systemId, content: xmlCharPtr); EXTDECL;

(**
 * notationDeclSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name: The name of the notation
 * @publicId: The public ID of the entity
 * @systemId: The system ID of the entity
 *
 * What to do when a notation declaration has been parsed.
 *)
  notationDeclSAXFunc = procedure(ctx: pointer; name, publicId, systemId: xmlCharPtr); EXTDECL;

(**
 * attributeDeclSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @elem:  the name of the element
 * @fullname:  the attribute name
 * @type:  the attribute type
 * @def:  the type of default value
 * @defaultValue: the attribute default value
 * @tree:  the tree of enumerated value set
 *
 * An attribute definition has been parsed.
 *)
  attributeDeclSAXFunc = procedure(ctx: pointer; elem, fullname: xmlCharPtr; _type, def: cint; defaultValue: xmlCharPtr; tree: xmlEnumerationPtr); EXTDECL;

(**
 * elementDeclSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  the element name
 * @type:  the element type
 * @content: the element value tree
 *
 * An element definition has been parsed.
 *)
  elementDeclSAXFunc = procedure(ctx: pointer; name: xmlCharPtr; _type: cint; content: xmlElementContentPtr); EXTDECL;

(**
 * unparsedEntityDeclSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name: The name of the entity
 * @publicId: The public ID of the entity
 * @systemId: The system ID of the entity
 * @notationName: the name of the notation
 *
 * What to do when an unparsed entity declaration is parsed.
 *)
  unparsedEntityDeclSAXFunc = procedure(ctx: pointer; name, publicId, systemId, notationName: xmlCharPtr); EXTDECL;

(**
 * setDocumentLocatorSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @loc: A SAX Locator
 *
 * Receive the document locator at startup, actually xmlDefaultSAXLocator.
 * Everything is available on the context, so this is useless in our case.
 *)
  setDocumentLocatorSAXFunc = procedure(ctx: pointer; loc: xmlSAXLocatorPtr); EXTDECL;

(**
 * startDocumentSAXFunc:
 * @ctx:  the user data (XML parser context)
 *
 * Called when the document start being processed.
 *)
  startDocumentSAXFunc = procedure(ctx: pointer); EXTDECL;

(**
 * endDocumentSAXFunc:
 * @ctx:  the user data (XML parser context)
 *
 * Called when the document end has been detected.
 *)
  endDocumentSAXFunc = procedure(ctx: pointer); EXTDECL;

(**
 * startElementSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  The element name, including namespace prefix
 * @atts:  An array of name/value attributes pairs, NULL terminated
 *
 * Called when an opening tag has been processed.
 *)
  startElementSAXFunc = procedure(ctx: pointer; name: xmlCharPtr; atts: xmlCharPtrPtr); EXTDECL;

(**
 * endElementSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  The element name
 *
 * Called when the end of an element has been detected.
 *)
  endElementSAXFunc = procedure(ctx: pointer; name: xmlCharPtr); EXTDECL;

(**
 * attributeSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  The attribute name, including namespace prefix
 * @value:  The attribute value
 *
 * Handle an attribute that has been read by the parser.
 * The default handling is to convert the attribute into an
 * DOM subtree and past it in a new xmlAttr element added to
 * the element.
 *)
  attributeSAXFunc = procedure(ctx: pointer; name, value: xmlCharPtr); EXTDECL;

(**
 * referenceSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @name:  The entity name
 *
 * Called when an entity reference is detected.
 *)
  referenceSAXFunc = procedure(ctx: pointer; name: xmlCharPtr); EXTDECL;

(**
 * charactersSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @ch:  a xmlChar string
 * @len: the number of xmlChar
 *
 * Receiving some chars from the parser.
 *)
  charactersSAXFunc = procedure(ctx: pointer; ch: xmlCharPtr; len: cint); EXTDECL;

(**
 * ignorableWhitespaceSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @ch:  a xmlChar string
 * @len: the number of xmlChar
 *
 * Receiving some ignorable whitespaces from the parser.
 * UNUSED: by default the DOM building will use characters.
 *)
  ignorableWhitespaceSAXFunc = procedure(ctx: pointer; ch: xmlCharPtr; len: cint); EXTDECL;

(**
 * processingInstructionSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @target:  the target name
 * @data: the PI data's
 *
 * A processing instruction has been parsed.
 *)
  processingInstructionSAXFunc = procedure(ctx: pointer; target, data: xmlCharPtr); EXTDECL;

(**
 * commentSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @value:  the comment content
 *
 * A comment has been parsed.
 *)
  commentSAXFunc = procedure(ctx: pointer; value: xmlCharPtr); EXTDECL;

(**
 * cdataBlockSAXFunc:
 * @ctx:  the user data (XML parser context)
 * @value:  The pcdata content
 * @len:  the block length
 *
 * Called when a pcdata block has been parsed.
 *)
  cdataBlockSAXFunc = procedure(ctx: pointer; value: xmlCharPtr; len: cint); EXTDECL;

(**
 * warningSAXFunc:
 * @ctx:  an XML parser context
 * @msg:  the message to display/transmit
 * @...:  extra parameters for the message display
 *
 * Display and format a warning messages, callback.
 *)
  warningSAXFunc = procedure(ctx: pointer; msg: pchar); cdecl; varargs;

(**
 * errorSAXFunc:
 * @ctx:  an XML parser context
 * @msg:  the message to display/transmit
 * @...:  extra parameters for the message display
 *
 * Display and format an error messages, callback.
 *)
  errorSAXFunc = procedure(ctx: pointer; msg: pchar); cdecl; varargs;

(**
 * fatalErrorSAXFunc:
 * @ctx:  an XML parser context
 * @msg:  the message to display/transmit
 * @...:  extra parameters for the message display
 *
 * Display and format fatal error messages, callback.
 * Note: so far fatalError() SAX callbacks are not used, error()
 *       get all the callbacks for errors.
 *)
  fatalErrorSAXFunc = procedure(ctx: pointer; msg: pchar); cdecl; varargs;

(**
 * isStandaloneSAXFunc:
 * @ctx:  the user data (XML parser context)
 *
 * Is this document tagged standalone?
 *
 * Returns 1 if true
 *)
  isStandaloneSAXFunc = function(ctx: pointer): cint; EXTDECL;

(**
 * hasInternalSubsetSAXFunc:
 * @ctx:  the user data (XML parser context)
 *
 * Does this document has an internal subset.
 *
 * Returns 1 if true
 *)
  hasInternalSubsetSAXFunc = function(ctx: pointer): cint; EXTDECL;

(**
 * hasExternalSubsetSAXFunc:
 * @ctx:  the user data (XML parser context)
 *
 * Does this document has an external subset?
 *
 * Returns 1 if true
 *)
  hasExternalSubsetSAXFunc = function(ctx: pointer): cint; EXTDECL;


(************************************************************************
 *									*
 *			The SAX version 2 API extensions		*
 *									*
 ************************************************************************)
(**
 * XML_SAX2_MAGIC:
 *
 * Special constant found in SAX2 blocks initialized fields
 *)
{$DEFINE XML_SAX2_MAGIC := $DEEDBEAF}

(**
 * startElementNsSAX2Func:
 * @ctx:  the user data (XML parser context)
 * @localname:  the local name of the element
 * @prefix:  the element namespace prefix if available
 * @URI:  the element namespace name if available
 * @nb_namespaces:  number of namespace definitions on that node
 * @namespaces:  pointer to the array of prefix/URI pairs namespace definitions
 * @nb_attributes:  the number of attributes on that node
 * @nb_defaulted:  the number of defaulted attributes. The defaulted
 *                  ones are at the end of the array
 * @attributes:  pointer to the array of (localname/prefix/URI/value/end)
 *               attribute values.
 *
 * SAX2 callback when an element start has been detected by the parser.
 * It provides the namespace informations for the element, as well as
 * the new namespace declarations on the element.
 *)
  startElementNsSAX2Func = procedure(ctx: pointer; localname, prefix, URI: xmlCharPtr; nb_namespaces: cint;
    namespaces: xmlCharPtrPtr; nb_attributes, nb_defaulted: cint; attributes: xmlCharPtrPtr); EXTDECL;

(**
 * endElementNsSAX2Func:
 * @ctx:  the user data (XML parser context)
 * @localname:  the local name of the element
 * @prefix:  the element namespace prefix if available
 * @URI:  the element namespace name if available
 *
 * SAX2 callback when an element end has been detected by the parser.
 * It provides the namespace informations for the element.
 *)
  endElementNsSAX2Func = procedure(ctx: pointer; localname, prefix, URI: xmlCharPtr); EXTDECL;

  xmlSAXHandler = record
    internalSubset: internalSubsetSAXFunc;
    isStandalone: isStandaloneSAXFunc;
    hasInternalSubset: hasInternalSubsetSAXFunc;
    hasExternalSubset: hasExternalSubsetSAXFunc;
    resolveEntity: resolveEntitySAXFunc;
    getEntity: getEntitySAXFunc;
    entityDecl: entityDeclSAXFunc;
    notationDecl: notationDeclSAXFunc;
    attributeDecl: attributeDeclSAXFunc;
    elementDecl: elementDeclSAXFunc;
    unparsedEntityDecl: unparsedEntityDeclSAXFunc;
    setDocumentLocator: setDocumentLocatorSAXFunc;
    startDocument: startDocumentSAXFunc;
    endDocument: endDocumentSAXFunc;
    startElement: startElementSAXFunc;
    endElement: endElementSAXFunc;
    reference: referenceSAXFunc;
    characters: charactersSAXFunc;
    ignorableWhitespace: ignorableWhitespaceSAXFunc;
    processingInstruction: processingInstructionSAXFunc;
    comment: commentSAXFunc;
    warning: warningSAXFunc;
    error: errorSAXFunc;
    fatalError: fatalErrorSAXFunc; (* unused error() get all the errors *)
    getParameterEntity: getParameterEntitySAXFunc;
    cdataBlock: cdataBlockSAXFunc;
    externalSubset: externalSubsetSAXFunc;
    initialized: cuint;
    (* The following fields are extensions available only on version 2 *)
    _private: pointer;
    startElementNs: startElementNsSAX2Func;
    endElementNs: endElementNsSAX2Func;
    serror: xmlStructuredErrorFunc;
  end;

(*
 * SAX Version 1
 *)
  xmlSAXHandlerV1 = record
    internalSubset: internalSubsetSAXFunc;
    isStandalone: isStandaloneSAXFunc;
    hasInternalSubset: hasInternalSubsetSAXFunc;
    hasExternalSubset: hasExternalSubsetSAXFunc;
    resolveEntity: resolveEntitySAXFunc;
    getEntity: getEntitySAXFunc;
    entityDecl: entityDeclSAXFunc;
    notationDecl: notationDeclSAXFunc;
    attributeDecl: attributeDeclSAXFunc;
    elementDecl: elementDeclSAXFunc;
    unparsedEntityDecl: unparsedEntityDeclSAXFunc;
    setDocumentLocator: setDocumentLocatorSAXFunc;
    startDocument: startDocumentSAXFunc;
    endDocument: endDocumentSAXFunc;
    startElement: startElementSAXFunc;
    endElement: endElementSAXFunc;
    reference: referenceSAXFunc;
    characters: charactersSAXFunc;
    ignorableWhitespace: ignorableWhitespaceSAXFunc;
    processingInstruction: processingInstructionSAXFunc;
    comment: commentSAXFunc;
    warning: warningSAXFunc;
    error: errorSAXFunc;
    fatalError: fatalErrorSAXFunc; (* unused error() get all the errors *)
    getParameterEntity: getParameterEntitySAXFunc;
    cdataBlock: cdataBlockSAXFunc;
    externalSubset: externalSubsetSAXFunc;
    initialized: cuint;
  end;


(**
 * xmlExternalEntityLoader:
 * @URL: The System ID of the resource requested
 * @ID: The Public ID of the resource requested
 * @context: the XML parser context
 *
 * External entity loaders types.
 *
 * Returns the entity input parser.
 *)
  xmlExternalEntityLoader = function(URL, ID: pchar; context: xmlParserCtxtPtr): xmlParserInputPtr; EXTDECL;

(**
 * xmlParserOption:
 *
 * This is the set of XML parser options that can be passed down
 * to the xmlReadDoc() and similar calls.
 *)
  xmlParserOption = type cint;
{$ENDIF}
{$IFDEF CONST}
  XML_PARSE_RECOVER = (1 shl 0); (* recover on errors *)
  XML_PARSE_NOENT = (1 shl 1); (* substitute entities *)
  XML_PARSE_DTDLOAD = (1 shl 2); (* load the external subset *)
  XML_PARSE_DTDATTR = (1 shl 3); (* default DTD attributes *)
  XML_PARSE_DTDVALID  = (1 shl 4); (* validate with the DTD *)
  XML_PARSE_NOERROR = (1 shl 5); (* suppress error reports *)
  XML_PARSE_NOWARNING = (1 shl 6); (* suppress warning reports *)
  XML_PARSE_PEDANTIC  = (1 shl 7); (* pedantic error reporting *)
  XML_PARSE_NOBLANKS  = (1 shl 8); (* remove blank nodes *)
  XML_PARSE_SAX1  = (1 shl 9); (* use the SAX1 interface internally *)
  XML_PARSE_XINCLUDE  = (1 shl 10);(* Implement XInclude substitition  *)
  XML_PARSE_NONET = (1 shl 11);(* Forbid network access *)
  XML_PARSE_NODICT  = (1 shl 12);(* Do not reuse the context dictionnary *)
  XML_PARSE_NSCLEAN = (1 shl 13);(* remove redundant namespaces declarations *)
  XML_PARSE_NOCDATA = (1 shl 14);(* merge CDATA as text nodes *)
  XML_PARSE_NOXINCNODE = (1 shl 15);(* do not generate XINCLUDE START/END nodes *)
  XML_PARSE_COMPACT   = (1 shl 16); (* compact small text nodes); no modification of
                                   the tree allowed afterwards (will possibly
           crash if you try to modify the tree) *)
{$ENDIF}

{$IFDEF TYPE}
  xmlFeature = (
    XML_WITH_THREAD = 1,
    XML_WITH_TREE = 2,
    XML_WITH_OUTPUT = 3,
    XML_WITH_PUSH = 4,
    XML_WITH_READER = 5,
    XML_WITH_PATTERN = 6,
    XML_WITH_WRITER = 7,
    XML_WITH_SAX1 = 8,
    XML_WITH_FTP = 9,
    XML_WITH_HTTP = 10,
    XML_WITH_VALID = 11,
    XML_WITH_HTML = 12,
    XML_WITH_LEGACY = 13,
    XML_WITH_C14N = 14,
    XML_WITH_CATALOG = 15,
    XML_WITH_XPATH = 16,
    XML_WITH_XPTR = 17,
    XML_WITH_XINCLUDE = 18,
    XML_WITH_ICONV = 19,
    XML_WITH_ISO8859X = 20,
    XML_WITH_UNICODE = 21,
    XML_WITH_REGEXP = 22,
    XML_WITH_AUTOMATA = 23,
    XML_WITH_EXPR = 24,
    XML_WITH_SCHEMAS = 25,
    XML_WITH_SCHEMATRON = 26,
    XML_WITH_MODULES = 27,
    XML_WITH_DEBUG = 28,
    XML_WITH_DEBUG_MEM = 29,
    XML_WITH_DEBUG_RUN = 30,
    XML_WITH_ZLIB = 31,
    XML_WITH_NONE = 99999 (* just to be sure of allocation size *)
  );

{$ENDIF}

{$IFDEF FUNCTION}
(*
 * Init/Cleanup
 *)
procedure xmlInitParser; EXTDECL; external xml2lib;
procedure xmlCleanupParser; EXTDECL; external xml2lib;

(*
 * Input functions
 *)
function xmlParserInputRead(_in: xmlParserInputPtr; len: cint): cint; EXTDECL; external xml2lib;
function xmlParserInputGrow(_in: xmlParserInputPtr; len: cint): cint; EXTDECL; external xml2lib;

(*
 * Basic parsing Interfaces
 *)
{$IFDEF LIBXML_SAX1_ENABLED}
function xmlParseDoc(cur: xmlCharPtr): xmlDocPtr; EXTDECL; external xml2lib;
function xmlParseFile(filename: pchar): xmlDocPtr; EXTDECL; external xml2lib;
function xmlParseMemory(buffer: pchar; size: cint): xmlDocPtr; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_SAX1_ENABLED *)
function xmlSubstituteEntitiesDefault(val: cint): cint; EXTDECL; external xml2lib;
function xmlKeepBlanksDefault(val: cint): cint; EXTDECL; external xml2lib;
procedure xmlStopParser(ctxt: xmlParserCtxtPtr); EXTDECL; external xml2lib;
function xmlPedanticParserDefault(val: cint): cint; EXTDECL; external xml2lib;
function xmlLineNumbersDefault(val: cint): cint; EXTDECL; external xml2lib;

{$IFDEF LIBXML_SAX1_ENABLED}
(*
 * Recovery mode
 *)
function xmlRecoverDoc(cur: xmlCharPtr): xmlDocPtr; EXTDECL; external xml2lib;
function xmlRecoverMemory(buffer: pchar; size: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlRecoverFile(filename: pchar): xmlDocPtr; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_SAX1_ENABLED *)

(*
 * Less common routines and SAX interfaces
 *)
function xmlParseDocument(ctxt: xmlParserCtxtPtr): cint; EXTDECL; external xml2lib;
function xmlParseExtParsedEnt(ctxt: xmlParserCtxtPtr): cint; EXTDECL; external xml2lib;
{$IFDEF LIBXML_SAX1_ENABLED}
function xmlSAXUserParseFile(sax: xmlSAXHandlerPtr; user_data: pointer; filename: pchar): cint; EXTDECL; external xml2lib;
function xmlSAXUserParseMemory(sax: xmlSAXHandlerPtr; user_data: pointer; buffer: pchar; size: cint): cint; EXTDECL; external xml2lib;
function xmlSAXParseDoc(sax: xmlSAXHandlerPtr; cur: xmlCharPtr; recovery: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlSAXParseMemory(sax: xmlSAXHandlerPtr; buffer: pchar; size: cint; recovery: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlSAXParseMemoryWithData(sax: xmlSAXHandlerPtr; buffer: pchar; size: cint; recovery: cint; data: pointer): xmlDocPtr; EXTDECL; external xml2lib;
function xmlSAXParseFile(sax: xmlSAXHandlerPtr; filename: pchar; recovery: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlSAXParseFileWithData(sax: xmlSAXHandlerPtr; filename: pchar; recovery: cint; data: pointer): xmlDocPtr; EXTDECL; external xml2lib;
function xmlSAXParseEntity(sax: xmlSAXHandlerPtr; filename: pchar): xmlDocPtr; EXTDECL; external xml2lib;
function xmlParseEntity(filename: pchar): xmlDocPtr; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_SAX1_ENABLED *)

{$IFDEF LIBXML_VALID_ENABLED}
function xmlSAXParseDTD(sax: xmlSAXHandlerPtr; ExternalID, SystemID: xmlCharPtr): xmlDtdPtr; EXTDECL; external xml2lib;
function xmlParseDTD(ExternalID, SystemID: xmlCharPtr): xmlDtdPtr; EXTDECL; external xml2lib;
function xmlIOParseDTD(sax: xmlSAXHandlerPtr; input: xmlParserInputBufferPtr; enc: xmlCharEncoding): xmlDtdPtr; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_VALID_ENABLE *)
{$IFDEF LIBXML_SAX1_ENABLED}
function xmlParseBalancedChunkMemory(doc: xmlDocPtr; sax: xmlSAXHandlerPtr; user_data: pointer; depth: cint; _string: xmlCharPtr; lst: xmlNodePtrPtr): cint; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_SAX1_ENABLED *)
function xmlParseInNodeContext(node: xmlNodePtr; data: pchar; datalen, options: cint; lst: xmlNodePtrPtr): xmlParserErrors; EXTDECL; external xml2lib;
{$IFDEF LIBXML_SAX1_ENABLED}
function xmlParseBalancedChunkMemoryRecover(doc: xmlDocPtr; sax: xmlSAXHandlerPtr; user_data: pointer;
  depth: cint; _string: xmlCharPtr; lst: xmlNodePtrPtr; recover: cint): cint; EXTDECL; external xml2lib;
function xmlParseExternalEntity(doc: xmlDocPtr; sax: xmlSAXHandlerPtr; user_data: pointer;
  depth: cint; URL, ID: xmlCharPtr; lst: xmlNodePtrPtr): cint; EXTDECL; external xml2lib;

{$ENDIF} (* LIBXML_SAX1_ENABLED *)
function xmlParseCtxtExternalEntity(ctx: xmlParserCtxtPtr; URL, ID: xmlCharPtr; lst: xmlNodePtrPtr): cint; EXTDECL; external xml2lib;

(*
 * Parser contexts handling.
 *)
function xmlNewParserCtxt: xmlParserCtxtPtr; EXTDECL; external xml2lib;
function xmlInitParserCtxt(ctxt: xmlParserCtxtPtr): cint; EXTDECL; external xml2lib;
procedure xmlClearParserCtxt(ctxt: xmlParserCtxtPtr); EXTDECL; external xml2lib;
procedure xmlFreeParserCtxt(ctxt: xmlParserCtxtPtr); EXTDECL; external xml2lib;
{$IFDEF LIBXML_SAX1_ENABLED}
procedure xmlSetupParserForBuffer(ctxt: xmlParserCtxtPtr; buffer: xmlCharPtr; filename: pchar); EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_SAX1_ENABLED *)
function xmlCreateDocParserCtxt(cur: xmlCharPtr): xmlParserCtxtPtr; EXTDECL; external xml2lib;

{$IFDEF LIBXML_LEGACY_ENABLED}
(*
 * Reading/setting optional parsing features.
 *)
function xmlGetFeaturesList(var len: cint; var result: pchar): cint; EXTDECL; external xml2lib;
function xmlGetFeature(ctxt: xmlParserCtxtPtr; name: pchar; result: pointer): cint; EXTDECL; external xml2lib;
function xmlSetFeature(ctxt: xmlParserCtxtPtr; name: pchar; value: pointer): cint; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_LEGACY_ENABLED *)

{$IFDEF LIBXML_PUSH_ENABLED}
(*
 * Interfaces for the Push mode.
 *)
function xmlCreatePushParserCtxt(sax: xmlSAXHandlerPtr; user_data: pointer; chunk: pchar; size: cint; filename: pchar): xmlParserCtxtPtr; EXTDECL; external xml2lib;
function xmlParseChunk(ctxt: xmlParserCtxtPtr; chunk: pchar; size, terminate: cint): cint; EXTDECL; external xml2lib;
{$ENDIF} (* LIBXML_PUSH_ENABLED *)

(*
 * Special I/O mode.
 *)
function xmlCreateIOParserCtxt(sax: xmlSAXHandlerPtr; user_data: pointer; ioread: xmlInputReadCallback;
  ioclose: xmlInputCloseCallback; ioctx: pointer; enc: xmlCharEncoding): xmlParserCtxtPtr; EXTDECL; external xml2lib;
function xmlNewIOInputStream(ctxt: xmlParserCtxtPtr; input: xmlParserInputBufferPtr; enc: xmlCharEncoding): xmlParserInputPtr; EXTDECL; external xml2lib;

(*
 * Node infos.
 *)
function xmlParserFindNodeInfo(ctxt: xmlParserCtxtPtr; node: xmlNodePtr): xmlParserNodeInfoPtr; EXTDECL; external xml2lib;
procedure xmlInitNodeInfoSeq(seq: xmlParserNodeInfoSeqPtr); EXTDECL; external xml2lib;
procedure xmlClearNodeInfoSeq(seq: xmlParserNodeInfoSeqPtr); EXTDECL; external xml2lib;
function xmlParserFindNodeInfoIndex(seq: xmlParserNodeInfoSeqPtr; node: xmlNodePtr): culong; EXTDECL; external xml2lib;
procedure xmlParserAddNodeInfo(ctxt: xmlParserCtxtPtr; info: xmlParserNodeInfoPtr); EXTDECL; external xml2lib;

(*
 * External entities handling actually implemented in xmlIO.
 *)
procedure xmlSetExternalEntityLoader(f: xmlExternalEntityLoader); EXTDECL; external xml2lib;
function xmlGetExternalEntityLoader(): xmlExternalEntityLoader; EXTDECL; external xml2lib;
function xmlLoadExternalEntity(URL, ID: pchar; ctxt: xmlParserCtxtPtr): xmlParserInputPtr; EXTDECL; external xml2lib;

(*
 * Index lookup, actually implemented in the encoding module
 *)
function xmlByteConsumed(ctxt: xmlParserCtxtPtr): culong; EXTDECL; external xml2lib;

(*
 * New set of simpler/more flexible APIs
 *)
procedure xmlCtxtReset(ctxt: xmlParserCtxtPtr); EXTDECL; external xml2lib;
function xmlCtxtResetPush(ctxt: xmlParserCtxtPtr; chunk: pchar; size: cint; filename, encoding: pchar): cint; EXTDECL; external xml2lib;
function xmlCtxtUseOptions(ctxt: xmlParserCtxtPtr; options: cint): cint; EXTDECL; external xml2lib;
function xmlReadDoc(cur: xmlCharPtr; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlReadFile(filename, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlReadMemory(buffer: pchar; size: cint; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlReadFd(fd: cint; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlReadIO(ioread: xmlInputReadCallback; ioclose: xmlInputCloseCallback; ioctx: pointer; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlCtxtReadDoc(ctxt: xmlParserCtxtPtr; cur: xmlCharPtr; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlCtxtReadFile(ctxt: xmlParserCtxtPtr; filename, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlCtxtReadMemory(ctxt: xmlParserCtxtPtr; buffer: pchar; size: cint; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlCtxtReadFd(ctxt: xmlParserCtxtPtr; fd: cint; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;
function xmlCtxtReadIO(ctxt: xmlParserCtxtPtr; ioread: xmlInputReadCallback; ioclose: xmlInputCloseCallback; ioctx: pchar; URL, encoding: pchar; options: cint): xmlDocPtr; EXTDECL; external xml2lib;

(*
 * Library wide options
 *)
(**
 * xmlFeature:
 *
 * Used to examine the existance of features that can be enabled
 * or disabled at compile-time.
 * They used to be called XML_FEATURE_xxx but this clashed with Expat
 *)
function xmlHasFeature(feature: xmlFeature): cint; EXTDECL; external xml2lib;
{$ENDIF}