libxml-rs 0.1.0-alpha.49

Native-Rust forensic reimplementation of libxml2+libxslt with C ABI drop-in replacement. Cross-version oracle matrix (libxml2 2.7.8-2.15.3, libxslt 1.1.26-1.1.45) with semantic epochs; full xmllint/xmlcatalog/xsltproc CLIs; differential-court-verified C API closure; three-DSO ELF packaging (libxml2.so.16 core + libxslt.so.1/libexslt.so.0 facades, upstream NEEDED chain); fail-closed oracle-isolated ABI-FUNCTION-SIGNATURE plane (SOURCE_PROTOTYPE + MACHINE_ABI fingerprints, zero silent omissions); Phase-12 real downstream substitution (binary/static/docker substitution, export-surface disposition, ELF version graphs); Phase-13 hostile audit courts (ABI/ownership/allocator/callbacks/failure/threads/oracle-contamination) byte-identical vs the system oracle incl. the upstream thread-local globals model; Phase-14 downstream custodian validation courts (lxml/Nokogiri/PHP/Debian). Test counts live in atlas/TEST_COUNTS.json, residuals in atlas/RESIDUAL_LEDGER.json (generated evidence).
Documentation
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
// Lint policy (11.1-Z seal): `missing_docs` and
// `missing_debug_implementations` are allowed here — the enums/constants
// mirror upstream C typedefs and #define values whose canonical
// documentation is the C header itself (the same rationale bindgen
// applies to generated bindings). The numeric values are the contract,
// verified against the oracle by the data-abi courts.
#![allow(missing_docs, missing_debug_implementations)]

//! C ABI type definitions — matching upstream libxml2/libxslt (§14).
//!
//! This module defines all public C-compatible types with exact layout,
//! size, and alignment matching the upstream headers.
//!
//! # Layout verification
//!
//! Every struct in this module must be verified against the oracle using
//! `offsetof` and `sizeof` probes compiled from the upstream headers.
//! See courts/abi-struct-*.json for verification receipts.
//!
//! # Phase 1 status
//!
//! All core types are defined. Verification against oracle is pending
//! Docker oracle build.
//!
//! # Source provenance
//!
//! All types derived from SRC-LIBXML2-2.15.3-TREE-H and related headers.
//! See atlas/SOURCES.md and atlas/api/ for the complete declaration inventory.
//!
//! # Upstream contract
//!
//! Mirrors the public libxml2/libxslt type surface at the 2.15.3/1.1.45 parity
//! target: `tree.h`, `parser.h`, `xpath.h`, `xmlerror.h`, `xmlreader.h`,
//! `xmlwriter.h`, `encoding.h` and the libxslt headers. Enum discriminants and
//! typedef values are the contract — C consumers compile against these exact
//! numbers.
//!
//! # Conceptual behavior
//!
//! This module implements the fundamental C-compatible types: `xmlChar` and
//! pointers, the `xmlElementType`/`xmlAttributeType`/`xmlEntityType` node
//! kinds, the `xmlErrorLevel`/`xmlErrorDomain` and `XML_ERR_*` error codes,
//! parser option flags, encoding ids, buffer allocation schemes and the
//! XML/XMLNS constant pointers. These feed every other ABI module.
//!
//! # Ownership & safety invariants
//!
//! Enum/flag types carry no ownership; the string constants are static
//! NUL-terminated slices never freed by callers. The numeric values must stay
//! fixed: shifting an `XML_ERR_*` constant changes every error code the parser
//! reports to C consumers.
//!
//! # Historical quirks & epochs
//!
//! R-000163 (11.1-M): the `XML_ERR_*` constants 64-96 were a synthetic
//! renumbered enum (e.g. SPACE_REQUIRED 89 instead of upstream 65,
//! TAG_NOT_FINISHED 96 instead of 77) and had to be corrected to the
//! header/upstream numbering — every error the parser emits uses them.
//! QUIRK-0001/LORE-0001 record the 2.9.0 default parser limits epoch (commit
//! `52d8ade7`) and LORE-0003 that `XML_PARSE_HUGE` (1<<19) existed since 2.8.0
//! as a near-no-op before the limits made it meaningful.
//!
//! # Deliberate oddities
//!
//! The `_deprecated_*`/`_unused_*` variants and historical enum values are
//! deliberately retained even when the current code never produces them — the
//! numeric surface is part of the ABI. Missing-docs is allowed here for the
//! same reason as structs.rs: the C headers are the documentation.
//!
//! # Proving courts
//!
//! The ERROR-001 differential probe (`courts/suites/data-abi/error-family-
//! probe.c`) verifies every error code/level/message byte-identical against
//! the oracle DSO (48/48 cases); the RUST-MIRROR-ABI court checks enum
//! discriminants; the header-compile court compiles every public
//! header against the candidate DSO.
//!
//! # Tempting simplifications that would break parity
//!
//! A tempting simplification is to renumber the error enums into a tidy
//! contiguous sequence — R-000163 proved that shifts error codes silently
//! (SPACE_REQUIRED 89 vs 65) and every C consumer matching on
//! `XML_ERR_SPACE_REQUIRED` would misbehave. The values must match the
//! upstream headers exactly, gaps and all.

use std::os::raw::c_int;

// ── Fundamental libxml2 types ───────────────────────────────────────────

/// Basic type for all xmlChars (UTF-8 encoded bytes).
pub type xmlChar = u8;

/// Pointer to xmlChar.
pub type xmlCharPtr = *mut xmlChar;

/// Const pointer to xmlChar.
pub type xmlConstCharPtr = *const xmlChar;

// ── Character encoding (xmlCharEncoding) ──────────────────────────────
//
// Source: encoding.h lines 18-60

/// Character encoding identifiers.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlCharEncoding {
    XML_CHAR_ENCODING_ERROR = -1,
    XML_CHAR_ENCODING_NONE = 0,
    XML_CHAR_ENCODING_UTF8 = 1,
    XML_CHAR_ENCODING_UTF16LE = 2,
    XML_CHAR_ENCODING_UTF16BE = 3,
    XML_CHAR_ENCODING_UCS4LE = 4,
    XML_CHAR_ENCODING_UCS4BE = 5,
    XML_CHAR_ENCODING_EBCDIC = 6,
    XML_CHAR_ENCODING_UCS4_2143 = 7,
    XML_CHAR_ENCODING_UCS4_3412 = 8,
    XML_CHAR_ENCODING_UCS2 = 9,
    XML_CHAR_ENCODING_8859_1 = 10,
    XML_CHAR_ENCODING_8859_2 = 11,
    XML_CHAR_ENCODING_8859_3 = 12,
    XML_CHAR_ENCODING_8859_4 = 13,
    XML_CHAR_ENCODING_8859_5 = 14,
    XML_CHAR_ENCODING_8859_6 = 15,
    XML_CHAR_ENCODING_8859_7 = 16,
    XML_CHAR_ENCODING_8859_8 = 17,
    XML_CHAR_ENCODING_8859_9 = 18,
    XML_CHAR_ENCODING_2022_JP = 19,
    XML_CHAR_ENCODING_SHIFT_JIS = 20,
    XML_CHAR_ENCODING_EUC_JP = 21,
    XML_CHAR_ENCODING_ASCII = 22,
}

// ── Node types (xmlElementType) ─────────────────────────────────────────
//
// Source: tree.h lines 162-184
// Provenance: SRC-LIBXML2-2.15.3-TREE-H

/// Type of an XML element or node.
///
/// These values are part of the ABI and MUST NOT be changed.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlElementType {
    XML_ELEMENT_NODE = 1,
    XML_ATTRIBUTE_NODE = 2,
    XML_TEXT_NODE = 3,
    XML_CDATA_SECTION_NODE = 4,
    XML_ENTITY_REF_NODE = 5,
    XML_ENTITY_NODE = 6,
    XML_PI_NODE = 7,
    XML_COMMENT_NODE = 8,
    XML_DOCUMENT_NODE = 9,
    XML_DOCUMENT_TYPE_NODE = 10,
    XML_DOCUMENT_FRAG_NODE = 11,
    XML_NOTATION_NODE = 12,
    XML_HTML_DOCUMENT_NODE = 13,
    XML_DTD_NODE = 14,
    XML_ELEMENT_DECL = 15,
    XML_ATTRIBUTE_DECL = 16,
    XML_ENTITY_DECL = 17,
    XML_NAMESPACE_DECL = 18,
    XML_XINCLUDE_START = 19,
    XML_XINCLUDE_END = 20,
}

/// Namespace type is typedef'd to xmlElementType in upstream.
pub type xmlNsType = xmlElementType;

/// XML_LOCAL_NAMESPACE macro equals XML_NAMESPACE_DECL.
pub const XML_LOCAL_NAMESPACE: xmlElementType = xmlElementType::XML_NAMESPACE_DECL;

// ── Document properties ─────────────────────────────────────────────────
//
// Source: tree.h lines 762-770

/// Document properties flags.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlDocProperties {
    XML_DOC_WELLFORMED = 1 << 0,
    XML_DOC_NSVALID = 1 << 1,
    XML_DOC_OLD10 = 1 << 2,
    XML_DOC_DTDVALID = 1 << 3,
    XML_DOC_XINCLUDE = 1 << 4,
    XML_DOC_USERBUILT = 1 << 5,
    XML_DOC_INTERNAL = 1 << 6,
    XML_DOC_HTML = 1 << 7,
}

// ── Buffer allocation scheme ────────────────────────────────────────────
//
// Source: tree.h lines 93-100

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlBufferAllocationScheme {
    XML_BUFFER_ALLOC_DOUBLEIT = 0,
    XML_BUFFER_ALLOC_EXACT = 1,
    XML_BUFFER_ALLOC_IMMUTABLE = 2,
    XML_BUFFER_ALLOC_IO = 3,
    XML_BUFFER_ALLOC_HYBRID = 4,
    XML_BUFFER_ALLOC_BOUNDED = 5,
}

// ── Attribute types ─────────────────────────────────────────────────────
//
// Source: tree.h lines 309-319

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlAttributeType {
    XML_ATTRIBUTE_CDATA = 1,
    XML_ATTRIBUTE_ID = 2,
    XML_ATTRIBUTE_IDREF = 3,
    XML_ATTRIBUTE_IDREFS = 4,
    XML_ATTRIBUTE_ENTITY = 5,
    XML_ATTRIBUTE_ENTITIES = 6,
    XML_ATTRIBUTE_NMTOKEN = 7,
    XML_ATTRIBUTE_NMTOKENS = 8,
    XML_ATTRIBUTE_ENUMERATION = 9,
    XML_ATTRIBUTE_NOTATION = 10,
}

// ── Attribute default modes ─────────────────────────────────────────────
//
// Source: tree.h lines 325-330

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlAttributeDefault {
    XML_ATTRIBUTE_NONE = 1,
    XML_ATTRIBUTE_REQUIRED = 2,
    XML_ATTRIBUTE_IMPLIED = 3,
    XML_ATTRIBUTE_FIXED = 4,
}

// ── Entity types ────────────────────────────────────────────────────────
//
// Source: entities.h lines 28-35

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlEntityType {
    XML_INTERNAL_GENERAL_ENTITY = 1,
    XML_EXTERNAL_GENERAL_PARSED_ENTITY = 2,
    XML_EXTERNAL_GENERAL_UNPARSED_ENTITY = 3,
    XML_INTERNAL_PARAMETER_ENTITY = 4,
    XML_EXTERNAL_PARAMETER_ENTITY = 5,
    XML_INTERNAL_PREDEFINED_ENTITY = 6,
}

// ── Element content types ───────────────────────────────────────────────
//
// Source: tree.h lines 396-401

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlElementContentType {
    XML_ELEMENT_CONTENT_PCDATA = 1,
    XML_ELEMENT_CONTENT_ELEMENT = 2,
    XML_ELEMENT_CONTENT_SEQ = 3,
    XML_ELEMENT_CONTENT_OR = 4,
}

// ── Element content occurrence ──────────────────────────────────────────
//
// Source: tree.h lines 406-410

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlElementContentOccur {
    XML_ELEMENT_CONTENT_ONCE = 1,
    XML_ELEMENT_CONTENT_OPT = 2,
    XML_ELEMENT_CONTENT_MULT = 3,
    XML_ELEMENT_CONTENT_PLUS = 4,
}

// ── Element type values ─────────────────────────────────────────────────
//
// Source: tree.h lines 443-450

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlElementTypeVal {
    XML_ELEMENT_TYPE_UNDEFINED = 0,
    XML_ELEMENT_TYPE_EMPTY = 1,
    XML_ELEMENT_TYPE_ANY = 2,
    XML_ELEMENT_TYPE_MIXED = 3,
    XML_ELEMENT_TYPE_ELEMENT = 4,
}

// ── Error levels ────────────────────────────────────────────────────────
//
// Source: xmlerror.h

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlErrorLevel {
    XML_ERR_NONE = 0,
    XML_ERR_WARNING = 1,
    XML_ERR_ERROR = 2,
    XML_ERR_FATAL = 3,
}

// ── Parser modes ────────────────────────────────────────────────────────

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum 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,
}

// ── Parser input state ──────────────────────────────────────────────────

/// `xmlParserInputState` (include/libxml/parser.h) — the parser's current
/// input state. `ctxt->instate` is an ABI-visible field: foreign consumers
/// compiled against the real libxml2 headers (PHP ext/xml's expat-compat
/// `compat.c` tests `instate == XML_PARSER_CONTENT` while resolving entity
/// references) compare against THESE exact values, so the numbering must
/// mirror the 2.15 header verbatim (SP-14.3.1-4, bug71592). Note that
/// `XML_PARSER_ENTITY_REF` was removed in 2.15 and `XML_PARSER_END_TAG` /
/// `XML_PARSER_ENTITY_DECL` etc. sit between `CDATA_SECTION` and
/// `ENTITY_VALUE`.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlParserInputState {
    XML_PARSER_EOF = -1,             /* nothing is to be parsed */
    XML_PARSER_START = 0,            /* nothing has been parsed */
    XML_PARSER_MISC = 1,             /* Misc* before int subset */
    XML_PARSER_PI = 2,               /* Within a processing instruction */
    XML_PARSER_DTD = 3,              /* within some DTD content */
    XML_PARSER_PROLOG = 4,           /* Misc* after internal subset */
    XML_PARSER_COMMENT = 5,          /* within a comment */
    XML_PARSER_START_TAG = 6,        /* within a start tag */
    XML_PARSER_CONTENT = 7,          /* within the content */
    XML_PARSER_CDATA_SECTION = 8,    /* within a CDATA section */
    XML_PARSER_END_TAG = 9,          /* within a closing tag */
    XML_PARSER_ENTITY_DECL = 10,     /* within an entity declaration */
    XML_PARSER_ENTITY_VALUE = 11,    /* within an entity value in a decl */
    XML_PARSER_ATTRIBUTE_VALUE = 12, /* within an attribute value */
    XML_PARSER_SYSTEM_LITERAL = 13,  /* within a SYSTEM value */
    XML_PARSER_EPILOG = 14,          /* the Misc* after the last end tag */
    XML_PARSER_IGNORE = 15,          /* within an IGNORED section */
    XML_PARSER_PUBLIC_LITERAL = 16,  /* within a PUBLIC value */
    XML_PARSER_XML_DECL = 17,        /* before XML decl (but after BOM) */
}

// ── XPath object types ──────────────────────────────────────────────────

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum xmlXPathObjectType {
    XPATH_UNDEFINED = 0,
    XPATH_NODESET = 1,
    XPATH_BOOLEAN = 2,
    XPATH_NUMBER = 3,
    XPATH_STRING = 4,
    XPATH_POINT = 5,
    XPATH_RANGE = 6,
    XPATH_LOCATIONSET = 7,
    XPATH_USERS = 8,
    XPATH_XSLT_TREE = 9,
}

// ── Parser option flags ─────────────────────────────────────────────────
//
// Source: parser.h

pub const XML_PARSE_RECOVER: c_int = 1 << 0;
pub const XML_PARSE_NOENT: c_int = 1 << 1;
pub const XML_PARSE_DTDLOAD: c_int = 1 << 2;
pub const XML_PARSE_DTDATTR: c_int = 1 << 3;
pub const XML_PARSE_DTDVALID: c_int = 1 << 4;
pub const XML_PARSE_NOERROR: c_int = 1 << 5;
pub const XML_PARSE_NOWARNING: c_int = 1 << 6;
pub const XML_PARSE_PEDANTIC: c_int = 1 << 7;
pub const XML_PARSE_NOBLANKS: c_int = 1 << 8;
pub const XML_PARSE_SAX1: c_int = 1 << 9;
pub const XML_PARSE_XINCLUDE: c_int = 1 << 10;
pub const XML_PARSE_NONET: c_int = 1 << 11;
pub const XML_PARSE_NODICT: c_int = 1 << 12;
pub const XML_PARSE_NSCLEAN: c_int = 1 << 13;
pub const XML_PARSE_NOCDATA: c_int = 1 << 14;
pub const XML_PARSE_NOXINCNODE: c_int = 1 << 15;
pub const XML_PARSE_COMPACT: c_int = 1 << 16;
pub const XML_PARSE_OLD10: c_int = 1 << 17;
pub const XML_PARSE_NOBASEFIX: c_int = 1 << 18;
pub const XML_PARSE_HUGE: c_int = 1 << 19;
pub const XML_PARSE_OLDSAX: c_int = 1 << 20;
pub const XML_PARSE_IGNORE_ENC: c_int = 1 << 21;
pub const XML_PARSE_BIG_LINES: c_int = 1 << 22;
pub const XML_PARSE_NO_XXE: c_int = 1 << 23;
pub const XML_PARSE_UNZIP: c_int = 1 << 24;
pub const XML_PARSE_NO_SYS_CATALOG: c_int = 1 << 25;
pub const XML_PARSE_CATALOG_PI: c_int = 1 << 26;
pub const XML_PARSE_SKIP_IDS: c_int = 1 << 27;

// ── Error domains ───────────────────────────────────────────────────────
//
// Source: xmlerror.h

pub const XML_FROM_NONE: c_int = 0;
pub const XML_FROM_PARSER: c_int = 1;
pub const XML_FROM_TREE: c_int = 2;
pub const XML_FROM_NAMESPACE: c_int = 3;
pub const XML_FROM_DTD: c_int = 4;
pub const XML_FROM_HTML: c_int = 5;
pub const XML_FROM_MEMORY: c_int = 6;
pub const XML_FROM_OUTPUT: c_int = 7;
pub const XML_FROM_IO: c_int = 8;
pub const XML_FROM_FTP: c_int = 9;
pub const XML_FROM_HTTP: c_int = 10;
pub const XML_FROM_XINCLUDE: c_int = 11;
pub const XML_FROM_XPATH: c_int = 12;
pub const XML_FROM_XPOINTER: c_int = 13;
pub const XML_FROM_REGEXP: c_int = 14;
pub const XML_FROM_DATATYPE: c_int = 15;
pub const XML_FROM_SCHEMASP: c_int = 16;
pub const XML_FROM_SCHEMASV: c_int = 17;
pub const XML_FROM_RELAXNGP: c_int = 18;
pub const XML_FROM_RELAXNGV: c_int = 19;
pub const XML_FROM_CATALOG: c_int = 20;
pub const XML_FROM_C14N: c_int = 21;
pub const XML_FROM_XSLT: c_int = 22;
pub const XML_FROM_VALID: c_int = 23;
pub const XML_FROM_CHECK: c_int = 24;
pub const XML_FROM_WRITER: c_int = 25;
pub const XML_FROM_MODULE: c_int = 26;
pub const XML_FROM_I18N: c_int = 27;
pub const XML_FROM_SCHEMATRONV: c_int = 28;
pub const XML_FROM_BUFFER: c_int = 29;
pub const XML_FROM_URI: c_int = 30;

// ── Parser error codes ──────────────────────────────────────────────────
//
// Source: xmlerror.h (xmlParserErrors enum)

pub const XML_ERR_OK: c_int = 0;
pub const XML_ERR_INTERNAL_ERROR: c_int = 1;
pub const XML_ERR_NO_MEMORY: c_int = 2;
pub const XML_ERR_DOCUMENT_START: c_int = 3;
pub const XML_ERR_DOCUMENT_EMPTY: c_int = 4;
pub const XML_ERR_DOCUMENT_END: c_int = 5;
pub const XML_ERR_INVALID_HEX_CHARREF: c_int = 6;
pub const XML_ERR_INVALID_DEC_CHARREF: c_int = 7;
pub const XML_ERR_INVALID_CHARREF: c_int = 8;
pub const XML_ERR_INVALID_CHAR: c_int = 9;
pub const XML_ERR_CHARREF_AT_EOF: c_int = 10;
pub const XML_ERR_CHARREF_IN_PROLOG: c_int = 11;
pub const XML_ERR_CHARREF_IN_EPILOG: c_int = 12;
pub const XML_ERR_CHARREF_IN_DTD: c_int = 13;
pub const XML_ERR_ENTITYREF_AT_EOF: c_int = 14;
pub const XML_ERR_ENTITYREF_IN_PROLOG: c_int = 15;
pub const XML_ERR_ENTITYREF_IN_EPILOG: c_int = 16;
pub const XML_ERR_ENTITYREF_IN_DTD: c_int = 17;
pub const XML_ERR_PEREF_AT_EOF: c_int = 18;
pub const XML_ERR_PEREF_IN_PROLOG: c_int = 19;
pub const XML_ERR_PEREF_IN_EPILOG: c_int = 20;
pub const XML_ERR_PEREF_IN_INT_SUBSET: c_int = 21;
pub const XML_ERR_ENTITYREF_NO_NAME: c_int = 22;
pub const XML_ERR_ENTITYREF_SEMICOL_MISSING: c_int = 23;
pub const XML_ERR_PEREF_NO_NAME: c_int = 24;
pub const XML_ERR_PEREF_SEMICOL_MISSING: c_int = 25;
pub const XML_ERR_UNDECLARED_ENTITY: c_int = 26;
pub const XML_WAR_UNDECLARED_ENTITY: c_int = 27;
pub const XML_ERR_UNPARSED_ENTITY: c_int = 28;
pub const XML_ERR_ENTITY_IS_EXTERNAL: c_int = 29;
pub const XML_ERR_ENTITY_IS_PARAMETER: c_int = 30;
pub const XML_ERR_UNKNOWN_ENCODING: c_int = 31;
pub const XML_ERR_UNSUPPORTED_ENCODING: c_int = 32;
pub const XML_ERR_STRING_NOT_STARTED: c_int = 33;
pub const XML_ERR_STRING_NOT_CLOSED: c_int = 34;
pub const XML_ERR_NS_DECL_ERROR: c_int = 35;
pub const XML_ERR_ENTITY_NOT_STARTED: c_int = 36;
pub const XML_ERR_ENTITY_NOT_FINISHED: c_int = 37;
pub const XML_ERR_LT_IN_ATTRIBUTE: c_int = 38;
pub const XML_ERR_ATTRIBUTE_NOT_STARTED: c_int = 39;
pub const XML_ERR_ATTRIBUTE_NOT_FINISHED: c_int = 40;
pub const XML_ERR_ATTRIBUTE_WITHOUT_VALUE: c_int = 41;
pub const XML_ERR_ATTRIBUTE_REDEFINED: c_int = 42;
pub const XML_ERR_LITERAL_NOT_STARTED: c_int = 43;
pub const XML_ERR_LITERAL_NOT_FINISHED: c_int = 44;
pub const XML_ERR_COMMENT_NOT_FINISHED: c_int = 45;
pub const XML_ERR_PI_NOT_STARTED: c_int = 46;
pub const XML_ERR_PI_NOT_FINISHED: c_int = 47;
pub const XML_ERR_NOTATION_NOT_STARTED: c_int = 48;
pub const XML_ERR_NOTATION_NOT_FINISHED: c_int = 49;
pub const XML_ERR_ATTLIST_NOT_STARTED: c_int = 50;
pub const XML_ERR_ATTLIST_NOT_FINISHED: c_int = 51;
pub const XML_ERR_MIXED_NOT_STARTED: c_int = 52;
pub const XML_ERR_MIXED_NOT_FINISHED: c_int = 53;
pub const XML_ERR_ELEMCONTENT_NOT_STARTED: c_int = 54;
pub const XML_ERR_ELEMCONTENT_NOT_FINISHED: c_int = 55;
pub const XML_ERR_XMLDECL_NOT_STARTED: c_int = 56;
pub const XML_ERR_XMLDECL_NOT_FINISHED: c_int = 57;
pub const XML_ERR_CONDSEC_NOT_STARTED: c_int = 58;
pub const XML_ERR_CONDSEC_NOT_FINISHED: c_int = 59;
pub const XML_ERR_EXT_SUBSET_NOT_FINISHED: c_int = 60;
pub const XML_ERR_DOCTYPE_NOT_FINISHED: c_int = 61;
pub const XML_ERR_MISPLACED_CDATA_END: c_int = 62;
pub const XML_ERR_CDATA_NOT_FINISHED: c_int = 63;
pub const XML_ERR_RESERVED_XML_NAME: c_int = 64;
pub const XML_ERR_SPACE_REQUIRED: c_int = 65;
pub const XML_ERR_SEPARATOR_REQUIRED: c_int = 66;
pub const XML_ERR_NMTOKEN_REQUIRED: c_int = 67;
pub const XML_ERR_NAME_REQUIRED: c_int = 68;
pub const XML_ERR_PCDATA_REQUIRED: c_int = 69;
pub const XML_ERR_URI_REQUIRED: c_int = 70;
pub const XML_ERR_PUBID_REQUIRED: c_int = 71;
pub const XML_ERR_LT_REQUIRED: c_int = 72;
pub const XML_ERR_GT_REQUIRED: c_int = 73;
pub const XML_ERR_LTSLASH_REQUIRED: c_int = 74;
pub const XML_ERR_EQUAL_REQUIRED: c_int = 75;
pub const XML_ERR_TAG_NAME_MISMATCH: c_int = 76;
pub const XML_ERR_TAG_NOT_FINISHED: c_int = 77;
pub const XML_ERR_STANDALONE_VALUE: c_int = 78;
pub const XML_ERR_ENCODING_NAME: c_int = 79;
pub const XML_ERR_HYPHEN_IN_COMMENT: c_int = 80;
pub const XML_ERR_INVALID_ENCODING: c_int = 81;
pub const XML_ERR_EXT_ENTITY_STANDALONE: c_int = 82;
pub const XML_ERR_CONDSEC_INVALID: c_int = 83;
pub const XML_ERR_VALUE_REQUIRED: c_int = 84;
pub const XML_ERR_NOT_WELL_BALANCED: c_int = 85;
pub const XML_ERR_EXTRA_CONTENT: c_int = 86;
pub const XML_ERR_ENTITY_CHAR_ERROR: c_int = 87;
pub const XML_ERR_ENTITY_PE_INTERNAL: c_int = 88;
pub const XML_ERR_ENTITY_LOOP: c_int = 89;
pub const XML_ERR_ENTITY_BOUNDARY: c_int = 90;
pub const XML_ERR_INVALID_URI: c_int = 91;
pub const XML_ERR_URI_FRAGMENT: c_int = 92;
pub const XML_WAR_CATALOG_PI: c_int = 93;
pub const XML_ERR_NO_DTD: c_int = 94;
pub const XML_ERR_RESOURCE_LIMIT: c_int = 114;
pub const XML_ERR_CONDSEC_INVALID_KEYWORD: c_int = 95;
pub const XML_ERR_VERSION_MISSING: c_int = 96;
pub const XML_ERR_ARGUMENT: c_int = 115;
pub const XML_ERR_REDECL_PREDEF_ENTITY: c_int = 117; /* entities.c xmlAddEntity */
pub const XML_ERR_INT_SUBSET_NOT_FINISHED: c_int = 118; /* parser.c xmlParseInternalSubset */
pub const XML_WAR_ENTITY_REDEFINED: c_int = 107; /* entities.c xmlAddEntity */
pub const XML_DTD_NO_DTD: c_int = 522; /* entities.c xmlAddEntity */
pub const XML_DTD_UNKNOWN_ELEM: c_int = 534; /* valid.c xmlValidateElement */
pub const XML_IO_ENOENT: c_int = 1524;
// Removed: duplicate of XML_ERR_NAME_TOO_LONG at line 414

// ── Parser limits ──────────────────────────────────────────────────────
//
// Source: parserInternals.h

pub const XML_MAX_TEXT_LENGTH: c_int = 10_000_000;
pub const XML_MAX_NAME_LENGTH: c_int = 50_000;
pub const XML_MAX_DICTIONARY_LIMIT: c_int = 1_000_000;
pub const XML_MAX_LOOKUP_LIMIT: c_int = 1_000_000;
pub const XML_MAX_HUGE_LENGTH: c_int = 100_000_000;

// ── XPath parser-context error codes (upstream xmlXPathError) ──────────
//
// Source: xpath.h (typedef enum { ... } xmlXPathError). The numeric values
// are part of the observable ABI (ctxt->error after evaluation).

pub const XPATH_EXPRESSION_OK: c_int = 0;
pub const XPATH_NUMBER_ERROR: c_int = 1;
pub const XPATH_UNFINISHED_LITERAL_ERROR: c_int = 2;
pub const XPATH_START_LITERAL_ERROR: c_int = 3;
pub const XPATH_VARIABLE_REF_ERROR: c_int = 4;
pub const XPATH_UNDEF_VARIABLE_ERROR: c_int = 5;
pub const XPATH_INVALID_PREDICATE_ERROR: c_int = 6;
pub const XPATH_EXPR_ERROR: c_int = 7;
pub const XPATH_UNCLOSED_ERROR: c_int = 8;
pub const XPATH_UNKNOWN_FUNC_ERROR: c_int = 9;
pub const XPATH_INVALID_OPERAND: c_int = 10;
pub const XPATH_INVALID_TYPE: c_int = 11;
pub const XPATH_INVALID_ARITY: c_int = 12;
pub const XPATH_INVALID_CTXT_SIZE: c_int = 13;
pub const XPATH_INVALID_CTXT_POSITION: c_int = 14;
pub const XPATH_MEMORY_ERROR: c_int = 15;
pub const XPTR_SYNTAX_ERROR: c_int = 16;
pub const XPTR_RESOURCE_ERROR: c_int = 17;
pub const XPTR_SUB_RESOURCE_ERROR: c_int = 18;
pub const XPATH_UNDEF_PREFIX_ERROR: c_int = 19;
pub const XPATH_ENCODING_ERROR: c_int = 20;
pub const XPATH_INVALID_CHAR_ERROR: c_int = 21;
pub const XPATH_INVALID_CTXT: c_int = 22;
pub const XPATH_STACK_ERROR: c_int = 23;
pub const XPATH_FORBID_VARIABLE_ERROR: c_int = 24;
pub const XPATH_OP_LIMIT_EXCEEDED: c_int = 25;
pub const XPATH_RECURSION_LIMIT_EXCEEDED: c_int = 26;

// ── Structured-error XPath code base (upstream xmlerror.h xmlParserErrors) ──
//
// Upstream xmlXPathErrFmt delivers `err->code = code + XML_XPATH_EXPRESSION_OK
// - XPATH_EXPRESSION_OK` — i.e. the 0-based xmlXPathError value offset by 1200
// (XML_XPATH_EXPRESSION_OK = 1200, XPATH_EXPRESSION_OK = 0) — so structured
// handlers observe 1207/1219-style codes, not 7/19. lxml's xmlerror.pxd
// matches these 1200-based values.

pub const XML_XPATH_EXPRESSION_OK: c_int = 1200;

pub const XML_MAX_NAMELEN: c_int = 100;
pub const XML_MAX_ATTRIBUTE_LENGTH: c_int = 500_000;

// ── Version constants ──────────────────────────────────────────────────

pub const LIBXML2_VERSION: &str = "2.15.3";
pub const LIBXML2_VERSION_MAJOR: c_int = 2;
pub const LIBXML2_VERSION_MINOR: c_int = 15;
pub const LIBXML2_VERSION_MICRO: c_int = 3;
pub const LIBXML2_VERSION_NUMBER: c_int = 21503;
pub const LIBXML2_VERSION_EXTRA: &str = "";

pub const LIBXSLT_VERSION: &str = "1.1.45";
pub const LIBXSLT_VERSION_MAJOR: c_int = 1;
pub const LIBXSLT_VERSION_MINOR: c_int = 1;
pub const LIBXSLT_VERSION_MICRO: c_int = 45;
pub const LIBXSLT_VERSION_NUMBER: c_int = 10145;
pub const LIBXSLT_VERSION_EXTRA: &str = "";

// ── SAX2 magic value ───────────────────────────────────────────────────

pub const XML_SAX2_MAGIC: c_int = 0xDEEDBEAFu32 as i32;