libxml-rs 0.1.0-alpha.4

Phase 3: I/O, encoding, URI, catalog, serialization, HTML. Native-Rust forensic reimplementation of libxml2+libxslt with C ABI drop-in replacement. 357 tests passing, full encoding subsystem, URI parser, OASIS catalog, HTML parser/serializer, tree serialization, custom I/O buffers.
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
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
//! C ABI struct definitions — exact upstream layout (§14, §17).
//!
//! Every struct in this module is laid out to match the corresponding
//! upstream C struct byte-for-byte on the target platform.
//!
//! # Upstream structs
//!
//! All structs derived from SRC-LIBXML2-2.15.3-TREE-H and related headers.
//! See the sub-agent extraction output for complete field-level archaeology.
//!
//! # Safety
//!
//! These structs are `#[repr(C)]` and may be passed across the FFI boundary.
//! Fields marked `_deprecated_*` or `_unused_*` are retained for ABI
//! compatibility even when the upstream has deprecated them.
//!
//! # Phase 1 status
//!
//! All core tree structs, error struct, parser context, SAX handler,
//! XPath context/object, and I/O structs are defined.
//!
//! # ABI verification
//!
//! Each struct must be verified with `offsetof`/`sizeof` probes compiled
//! from upstream headers. See courts/abi-struct-*.json for receipts.

use crate::abi::callbacks::*;
use crate::abi::types::*;
use std::os::raw::{c_char, c_int, c_long, c_uint, c_ulong, c_ushort, c_void};

// ── Forward declarations ────────────────────────────────────────────────
//
// These are the internal struct tags. In C, these are typedef'd to
// pointer types. We define them as opaque handles or full structs
// depending on whether the struct is public or opaque.

// Opaque types (defined in .c files, not exposed in headers):
//   _xmlDict, _xmlHashTable, _xmlList, _xmlRegexp, _xmlCatalog,
//   _xmlXPathCompExpr, _xmlAutomata, _xmlPattern

// ── xmlBuffer ───────────────────────────────────────────────────────────
//
// Source: tree.h lines 109-126

/// Buffer structure. Deprecated in favor of xmlBuf.
#[repr(C)]
pub struct _xmlBuffer {
    pub content: *mut xmlChar,   // The buffer content UTF8 (deprecated)
    pub use_: c_uint,            // The buffer size used (deprecated)
    pub size: c_uint,            // The buffer size (deprecated)
    pub alloc: c_int,            // The realloc method (deprecated)
    pub contentIO: *mut xmlChar, // In IO mode may have different base (deprecated)
}

// ── xmlNotation ─────────────────────────────────────────────────────────
//
// Source: tree.h lines 297-305

/// Notation declaration.
#[repr(C)]
pub struct _xmlNotation {
    pub name: *const xmlChar,     // Notation name
    pub PublicID: *const xmlChar, // Public identifier, if any
    pub SystemID: *const xmlChar, // System identifier, if any
}

// ── xmlEnumeration ──────────────────────────────────────────────────────
//
// Source: tree.h lines 341-345

/// Enumeration value for attribute declarations.
#[repr(C)]
pub struct _xmlEnumeration {
    pub next: *mut _xmlEnumeration, // Next in enumeration (deprecated)
    pub name: *const xmlChar,       // Enumeration value
}

// ── xmlAttribute (declaration) ──────────────────────────────────────────
//
// Source: tree.h lines 357-391
// NOTE: This is the ATTRIBUTE DECLARATION struct, not attribute node.
// Attribute node is _xmlAttr below.

/// Attribute declaration from DTD.
#[repr(C)]
pub struct _xmlAttribute {
    pub _private: *mut c_void,   // Application data
    pub type_: c_int,            // XML_ATTRIBUTE_DECL
    pub name: *const xmlChar,    // Attribute name
    pub children: *mut _xmlNode, // NULL
    pub last: *mut _xmlNode,     // NULL
    pub parent: *mut _xmlDtd,    // DTD
    pub next: *mut _xmlNode,     // Next sibling
    pub prev: *mut _xmlNode,     // Previous sibling
    pub doc: *mut _xmlDoc,       // Containing document

    pub nexth: *mut _xmlAttribute,  // Next in hash table
    pub atype: c_int,               // Attribute type
    pub def: c_int,                 // Attribute default
    pub defaultValue: *mut xmlChar, // Default value
    pub tree: *mut _xmlEnumeration, // Enumeration tree (deprecated)
    pub prefix: *const xmlChar,     // Namespace prefix
    pub elem: *const xmlChar,       // Element name
}

// ── xmlElementContent ───────────────────────────────────────────────────
//
// Source: tree.h lines 423-438

/// Element content model.
#[repr(C)]
pub struct _xmlElementContent {
    pub type_: c_int,                    // PCDATA, ELEMENT, SEQ or OR (deprecated)
    pub ocur: c_int,                     // ONCE, OPT, MULT or PLUS (deprecated)
    pub name: *const xmlChar,            // Element name (deprecated)
    pub c1: *mut _xmlElementContent,     // First child (deprecated)
    pub c2: *mut _xmlElementContent,     // Second child (deprecated)
    pub parent: *mut _xmlElementContent, // Parent (deprecated)
    pub prefix: *const xmlChar,          // Namespace prefix (deprecated)
}

// ── xmlNs ───────────────────────────────────────────────────────────────
//
// Source: tree.h lines 501-512

/// Namespace declaration or XPath namespace node.
#[repr(C)]
pub struct _xmlNs {
    pub next: *mut _xmlNs,      // Next namespace
    pub type_: c_int,           // XML_NAMESPACE_DECL
    pub href: *const xmlChar,   // Namespace URI
    pub prefix: *const xmlChar, // Namespace prefix
    pub _private: *mut c_void,  // Application data
    pub context: *mut _xmlDoc,  // Normally an xmlDoc (deprecated)
}

// ── xmlDtd ──────────────────────────────────────────────────────────────
//
// Source: tree.h lines 538-564

/// DTD (Document Type Definition).
#[repr(C)]
pub struct _xmlDtd {
    pub _private: *mut c_void,   // Application data
    pub type_: c_int,            // XML_DTD_NODE
    pub name: *const xmlChar,    // Name of the DTD
    pub children: *mut _xmlNode, // First child
    pub last: *mut _xmlNode,     // Last child
    pub parent: *mut _xmlDoc,    // Parent node (document)
    pub next: *mut _xmlNode,     // Next sibling
    pub prev: *mut _xmlNode,     // Previous sibling
    pub doc: *mut _xmlDoc,       // Containing document
    // End of common part
    pub notations: *mut c_void,   // Hash table for notations
    pub elements: *mut c_void,    // Hash table for elements
    pub attributes: *mut c_void,  // Hash table for attributes
    pub entities: *mut c_void,    // Hash table for entities
    pub ExternalID: *mut xmlChar, // Public identifier
    pub SystemID: *mut xmlChar,   // System identifier
    pub pentities: *mut c_void,   // Hash table for parameter entities
}

// ── xmlAttr ─────────────────────────────────────────────────────────────
//
// Source: tree.h lines 595-615

/// Attribute node.
#[repr(C)]
pub struct _xmlAttr {
    pub _private: *mut c_void,   // Application data
    pub type_: c_int,            // XML_ATTRIBUTE_NODE
    pub name: *const xmlChar,    // Local name
    pub children: *mut _xmlNode, // First child (text value)
    pub last: *mut _xmlNode,     // Last child
    pub parent: *mut _xmlNode,   // Parent node
    pub next: *mut _xmlAttr,     // Next sibling (attribute)
    pub prev: *mut _xmlAttr,     // Previous sibling (attribute)
    pub doc: *mut _xmlDoc,       // Containing document
    pub ns: *mut _xmlNs,         // Namespace if any
    pub atype: c_int,            // Attribute type
    pub psvi: *mut c_void,       // Type/PSVI information
    pub id: *mut c_void,         // ID struct (deprecated)
}

// ── xmlNode ─────────────────────────────────────────────────────────────
//
// Source: tree.h lines 645-688

/// XML node — the core tree structure.
#[repr(C)]
pub struct _xmlNode {
    pub _private: *mut c_void,   // Application data
    pub type_: c_int,            // Type enum
    pub name: *const xmlChar,    // Node name
    pub children: *mut _xmlNode, // First child
    pub last: *mut _xmlNode,     // Last child
    pub parent: *mut _xmlNode,   // Parent node (NULL for documents)
    pub next: *mut _xmlNode,     // Next sibling
    pub prev: *mut _xmlNode,     // Previous sibling
    pub doc: *mut _xmlDoc,       // Associated document
    // End of common part
    pub ns: *mut _xmlNs,           // Namespace of element
    pub content: *mut xmlChar,     // Content (text/comment/PI)
    pub properties: *mut _xmlAttr, // First attribute of element
    pub nsDef: *mut _xmlNs,        // First namespace definition
    pub psvi: *mut c_void,         // Type/PSVI information
    pub line: c_ushort,            // Line number
    pub extra: c_ushort,           // Extra data for XPath/XSLT
}

// ── xmlDoc ──────────────────────────────────────────────────────────────
//
// Source: tree.h lines 787-845

/// XML Document.
#[repr(C)]
pub struct _xmlDoc {
    pub _private: *mut c_void,   // Application data
    pub type_: c_int,            // XML_DOCUMENT_NODE or XML_HTML_DOCUMENT_NODE
    pub name: *mut c_char,       // NULL
    pub children: *mut _xmlNode, // First child (root element)
    pub last: *mut _xmlNode,     // Last child
    pub parent: *mut _xmlNode,   // Parent node
    pub next: *mut _xmlNode,     // Next sibling
    pub prev: *mut _xmlNode,     // Previous sibling
    pub doc: *mut _xmlDoc,       // Reference to itself
    // End of common part
    pub compression: c_int,      // Level of zlib compression
    pub standalone: c_int,       // Standalone document status
    pub intSubset: *mut _xmlDtd, // Internal subset
    pub extSubset: *mut _xmlDtd, // External subset
    pub oldNs: *mut _xmlNs,      // Old namespace (used during parsing)
    pub version: *mut xmlChar,   // Version string from XML declaration
    pub encoding: *mut xmlChar,  // Actual encoding
    pub ids: *mut c_void,        // Hash table for ID attributes
    pub refs: *mut c_void,       // Hash table for IDREFs (deprecated)
    pub URL: *mut xmlChar,       // URI of the document
    pub charset: c_int,          // Unused (encoding indicator)
    pub dict: *mut c_void,       // Dictionary for names (opaque _xmlDict)
    pub psvi: *mut c_void,       // Type/PSVI information
    pub parseFlags: c_int,       // Parser options used
    pub properties: c_int,       // Document properties flags
}

// ── xmlEntity ───────────────────────────────────────────────────────────
//
// Source: entities.h lines 42-74

/// Entity declaration.
#[repr(C)]
pub struct _xmlEntity {
    pub _private: *mut c_void,      // Application data
    pub type_: c_int,               // XML_ENTITY_DECL (must be second!)
    pub name: *const xmlChar,       // Entity name
    pub children: *mut _xmlNode,    // First child link
    pub last: *mut _xmlNode,        // Last child link
    pub parent: *mut _xmlDtd,       // -> DTD
    pub next: *mut _xmlNode,        // Next sibling link
    pub prev: *mut _xmlNode,        // Previous sibling link
    pub doc: *mut _xmlDoc,          // The containing document
    pub orig: *mut xmlChar,         // Content without ref substitution
    pub content: *mut xmlChar,      // Content or ndata if unparsed
    pub length: c_int,              // The content length
    pub etype: c_int,               // The entity type
    pub ExternalID: *const xmlChar, // External identifier for PUBLIC
    pub SystemID: *const xmlChar,   // URI for SYSTEM or PUBLIC Entity
    pub nexte: *mut _xmlEntity,     // Unused
    pub URI: *const xmlChar,        // The full URI as computed
    pub owner: c_int,               // Unused
    pub flags: c_int,               // Various flags
    pub expandedSize: c_ulong,      // Expanded size
}

// ── xmlError ────────────────────────────────────────────────────────────
//
// Source: xmlerror.h

/// Structured error information.
#[repr(C)]
pub struct _xmlError {
    pub domain: c_int,        // Error domain
    pub code: c_int,          // Error code
    pub message: *mut c_char, // Human-readable error message
    pub level: c_int,         // Error level
    pub file: *mut c_char,    // Filename if available
    pub line: c_int,          // Line number if available
    pub str1: *mut c_char,    // Extra string information
    pub str2: *mut c_char,    // Extra string information
    pub str3: *mut c_char,    // Extra string information
    pub int1: c_int,          // Extra number information
    pub int2: c_int,          // Column number if available
    pub ctxt: *mut c_void,    // Parser context if available
    pub node: *mut c_void,    // Node if available
}

// ── xmlParserInput ──────────────────────────────────────────────────────
//
// Source: parser.h

/// Parser input stream.
#[repr(C)]
pub struct _xmlParserInput {
    pub buf: *mut _xmlParserInputBuffer, // Input buffer (deprecated)
    pub filename: *const c_char,         // The filename or URI (deprecated)
    pub directory: *const c_char,        // Unused (deprecated)
    pub base: *const xmlChar,            // Base of the array to parse
    pub cur: *const xmlChar,             // Current char being parsed (deprecated)
    pub end: *const xmlChar,             // End of the array to parse
    pub length: c_int,                   // Unused (deprecated)
    pub line: c_int,                     // Current line (deprecated)
    pub col: c_int,                      // Current column (deprecated)
    pub consumed: c_ulong,               // How many xmlChars consumed (deprecated)
    pub free: Option<unsafe extern "C" fn(*mut c_char)>, // Deallocation func (deprecated)
    pub encoding: *const xmlChar,        // Unused (deprecated)
    pub version: *const xmlChar,         // The version string for entity (deprecated)
    pub flags: c_int,                    // Flags (deprecated)
    pub id: c_int,                       // Unique identifier (deprecated)
    pub parentConsumed: c_ulong,         // Unused (deprecated)
    pub entity: *mut _xmlEntity,         // Entity if any (deprecated)
}

// ── xmlParserInputBuffer ────────────────────────────────────────────────
//
// Source: xmlIO.h

/// Parser input buffer.
#[repr(C)]
pub struct _xmlParserInputBuffer {
    pub context: *mut c_void,                         // (deprecated)
    pub readcallback: Option<xmlInputReadCallback>,   // (deprecated)
    pub closecallback: Option<xmlInputCloseCallback>, // (deprecated)
    pub encoder: *mut c_void,                         // I18N converter (deprecated)
    pub buffer: *mut c_void,                          // Local buffer (deprecated)
    pub raw: *mut c_void,                             // Raw input buffer (deprecated)
    pub compressed: c_int,                            // Compression flag (deprecated)
    pub error: c_int,                                 // (deprecated)
    pub rawconsumed: c_ulong,                         // (deprecated)
}

// ── xmlOutputBuffer ─────────────────────────────────────────────────────
//
// Source: xmlIO.h

/// Output buffer.
#[repr(C)]
pub struct _xmlOutputBuffer {
    pub context: *mut c_void,                          // (deprecated)
    pub writecallback: Option<xmlOutputWriteCallback>, // (deprecated)
    pub closecallback: Option<xmlOutputCloseCallback>, // (deprecated)
    pub encoder: *mut c_void,                          // I18N converter
    pub buffer: *mut c_void,                           // Local buffer
    pub conv: *mut c_void,                             // Output conversion buffer
    pub written: c_int,                                // Total bytes written
    pub error: c_int,                                  // Error flag
}

// ── xmlCharEncodingHandler ───────────────────────────────────────────────
//
// Source: encoding.h

/// Character encoding conversion handler.
#[repr(C)]
pub struct _xmlCharEncodingHandler {
    pub name: *mut c_char,                              // Encoding name
    pub input: c_int,                                   // Input xmlCharEncoding
    pub output: c_int,                                  // Output xmlCharEncoding
    pub input_func: Option<xmlCharEncodingInputFunc>,   // Input conversion func
    pub output_func: Option<xmlCharEncodingOutputFunc>, // Output conversion func
    pub iconv_in: *mut c_void,                          // Iconv descriptor for input
    pub iconv_out: *mut c_void,                         // Iconv descriptor for output
}

// ── xmlBuf ──────────────────────────────────────────────────────────────
//
// Source: tree.h

/// Buffer structure (modern replacement for xmlBuffer).
#[repr(C)]
pub struct _xmlBuf {
    pub content: *mut xmlChar, // The buffer content UTF8
    pub use_: c_uint,          // The buffer size used
    pub size: c_uint,          // The buffer size
    pub alloc: c_int,          // The realloc method
    pub error: c_int,          // Error flag
    pub buffer: c_int,         // Is this a buffer from xmlBuffer?
    pub io: c_int,             // In IO mode?
}

// ── xmlSAXHandler ───────────────────────────────────────────────────────
//
// Source: parser.h

/// SAX event handler structure.
#[repr(C)]
pub struct _xmlSAXHandler {
    pub internalSubset: Option<internalSubsetSAXFunc>,
    pub isStandalone: Option<isStandaloneSAXFunc>,
    pub hasInternalSubset: Option<hasInternalSubsetSAXFunc>,
    pub hasExternalSubset: Option<hasExternalSubsetSAXFunc>,
    pub resolveEntity: Option<resolveEntitySAXFunc>,
    pub getEntity: Option<getEntitySAXFunc>,
    pub entityDecl: Option<entityDeclSAXFunc>,
    pub notationDecl: Option<notationDeclSAXFunc>,
    pub attributeDecl: Option<attributeDeclSAXFunc>,
    pub elementDecl: Option<elementDeclSAXFunc>,
    pub unparsedEntityDecl: Option<unparsedEntityDeclSAXFunc>,
    pub setDocumentLocator: Option<setDocumentLocatorSAXFunc>,
    pub startDocument: Option<startDocumentSAXFunc>,
    pub endDocument: Option<endDocumentSAXFunc>,
    pub startElement: Option<startElementSAXFunc>,
    pub endElement: Option<endElementSAXFunc>,
    pub reference: Option<referenceSAXFunc>,
    pub characters: Option<charactersSAXFunc>,
    pub ignorableWhitespace: Option<ignorableWhitespaceSAXFunc>,
    pub processingInstruction: Option<processingInstructionSAXFunc>,
    pub comment: Option<commentSAXFunc>,
    pub warning: Option<warningSAXFunc>,
    pub error: Option<errorSAXFunc>,
    pub fatalError: Option<fatalErrorSAXFunc>,
    pub getParameterEntity: Option<getParameterEntitySAXFunc>,
    pub cdataBlock: Option<cdataBlockSAXFunc>,
    pub externalSubset: Option<externalSubsetSAXFunc>,
    pub initialized: c_uint,
    pub _private: *mut c_void,
    pub startElementNs: Option<startElementNsSAX2Func>,
    pub endElementNs: Option<endElementNsSAX2Func>,
    pub serror: Option<xmlStructuredErrorFunc>,
}

// ── xmlParserCtxt ───────────────────────────────────────────────────────
//
// Source: parser.h

/// Parser context — the primary parsing state structure.
#[repr(C)]
pub struct _xmlParserCtxt {
    pub sax: *mut _xmlSAXHandler, // SAX handler (deprecated)
    pub userData: *mut c_void,    // User data (deprecated)
    pub myDoc: *mut _xmlDoc,      // Document being built (deprecated)
    pub wellFormed: c_int,        // Is document well formed? (deprecated)
    pub replaceEntities: c_int,   // Replace entities? (deprecated)
    pub version: *mut xmlChar,    // XML version string (deprecated)
    pub encoding: *mut xmlChar,   // Declared encoding (deprecated)
    pub standalone: c_int,        // Standalone document (deprecated)
    pub html: c_int,              // HTML document (deprecated)
    // Input stream stack
    pub input: *mut _xmlParserInput,         // Current input stream
    pub inputNr: c_int,                      // Number of current input streams
    pub inputMax: c_int,                     // Max number of input streams (deprecated)
    pub inputTab: *mut *mut _xmlParserInput, // Stack of inputs
    // Node analysis stack
    pub node: *mut _xmlNode,         // Current element (deprecated)
    pub nodeNr: c_int,               // Depth of parsing stack (deprecated)
    pub nodeMax: c_int,              // Max depth (deprecated)
    pub nodeTab: *mut *mut _xmlNode, // Array of nodes (deprecated)
    // Node info
    pub record_info: c_int,             // Whether node info should be kept
    pub node_seq: xmlParserNodeInfoSeq, // Info about each node parsed (deprecated)
    // Error
    pub errNo: c_int, // Error code (deprecated)
    // Reference and external subset
    pub hasExternalSubset: c_int, // (deprecated)
    pub hasPErefs: c_int,         // (deprecated)
    pub external: c_int,          // (deprecated)
    pub valid: c_int,             // Is document valid? (deprecated)
    pub validate: c_int,          // Validate flag (deprecated)
    pub vctxt: _xmlValidCtxt,     // Validity context
    // Push parser state
    pub instate: c_int,         // (deprecated)
    pub token: c_int,           // (deprecated)
    pub directory: *mut c_char, // Document directory (deprecated)
    // Node name stack
    pub name: *const xmlChar,         // Current parsed Node (deprecated)
    pub nameNr: c_int,                // (deprecated)
    pub nameMax: c_int,               // (deprecated)
    pub nameTab: *mut *const xmlChar, // (deprecated)
    // Misc
    pub nbChars: c_long,            // (deprecated)
    pub checkIndex: c_long,         // (deprecated)
    pub keepBlanks: c_int,          // (deprecated)
    pub disableSAX: c_int,          // (deprecated)
    pub inSubset: c_int,            // DTD parsing state (deprecated)
    pub intSubName: *const xmlChar, // Internal subset name (deprecated)
    pub extSubURI: *mut xmlChar,    // External subset URI (deprecated)
    pub extSubSystem: *mut xmlChar, // External subset public ID (deprecated)
    // xml:space values
    pub space: *mut c_int,    // (deprecated)
    pub spaceNr: c_int,       // (deprecated)
    pub spaceMax: c_int,      // (deprecated)
    pub spaceTab: *mut c_int, // (deprecated)
    // Entity loop prevention
    pub depth: c_int,                 // (deprecated)
    pub entity: *mut _xmlParserInput, // (deprecated)
    pub charset: c_int,               // (deprecated)
    pub nodelen: c_int,               // (deprecated)
    pub nodemem: c_int,               // (deprecated)
    pub pedantic: c_int,              // (deprecated)
    pub _private: *mut c_void,        // User data (deprecated)
    pub loadsubset: c_int,            // Load external subset (deprecated)
    pub linenumbers: c_int,           // (deprecated)
    pub catalogs: *mut c_void,        // (deprecated)
    pub recovery: c_int,              // Recovery mode (deprecated)
    pub progressive: c_int,           // (deprecated)
    pub dict: *mut c_void,            // Dictionary (deprecated)
    pub atts: *mut *const xmlChar,    // Attributes array (deprecated)
    pub maxatts: c_int,               // (deprecated)
    pub docdict: c_int,               // (deprecated)
    // Pre-interned strings
    pub str_xml: *const xmlChar,    // (deprecated)
    pub str_xmlns: *const xmlChar,  // (deprecated)
    pub str_xml_ns: *const xmlChar, // (deprecated)
    // New SAX mode
    pub sax2: c_int,                // (deprecated)
    pub nsNr: c_int,                // (deprecated)
    pub nsMax: c_int,               // (deprecated)
    pub nsTab: *mut *const xmlChar, // (deprecated)
    pub attallocs: *mut c_uint,     // (deprecated)
    pub pushTab: *mut c_void,       // xmlStartTag (deprecated)
    pub attsDefault: *mut c_void,   // (deprecated)
    pub attsSpecial: *mut c_void,   // (deprecated)
    pub nsWellFormed: c_int,        // (deprecated)
    pub options: c_int,             // Extra options (deprecated)
    pub dictNames: c_int,           // (deprecated)
    // Streaming
    pub freeElemsNr: c_int,       // (deprecated)
    pub freeElems: *mut _xmlNode, // (deprecated)
    pub freeAttrsNr: c_int,       // (deprecated)
    pub freeAttrs: *mut _xmlAttr, // (deprecated)
    pub lastError: _xmlError,     // Last error info (deprecated)
    pub parseMode: c_int,         // (deprecated)
    pub nbentities: c_ulong,      // (deprecated)
    pub sizeentities: c_ulong,    // (deprecated)
    // HTML non-recursive parser
    pub nodeInfo: *mut c_void,    // (deprecated)
    pub nodeInfoNr: c_int,        // (deprecated)
    pub nodeInfoMax: c_int,       // (deprecated)
    pub nodeInfoTab: *mut c_void, // (deprecated)
    pub input_id: c_int,          // (deprecated)
    pub sizeentcopy: c_ulong,     // (deprecated)
    pub endCheckState: c_int,     // (deprecated)
    pub nbErrors: c_ushort,       // (deprecated)
    pub nbWarnings: c_ushort,     // (deprecated)
    pub maxAmpl: c_uint,          // (deprecated)
    // Namespace database
    pub nsdb: *mut c_void,     // (deprecated)
    pub attrHashMax: c_uint,   // (deprecated)
    pub attrHash: *mut c_void, // (deprecated)
    // Error handler
    pub errorHandler: Option<xmlStructuredErrorFunc>, // (deprecated)
    pub errorCtxt: *mut c_void,                       // (deprecated)
    // Resource loader
    pub resourceLoader: Option<xmlResourceLoader>, // (deprecated)
    pub resourceCtxt: *mut c_void,                 // (deprecated)
    // Encoding conversion
    pub convImpl: Option<xmlCharEncConvImpl>, // (deprecated)
    pub convCtxt: *mut c_void,                // (deprecated)
}

// ── xmlValidCtxt ────────────────────────────────────────────────────────
//
// Source: valid.h

/// Validation context.
#[repr(C)]
pub struct _xmlValidCtxt {
    pub userData: *mut c_void,                   // User specific data
    pub error: Option<xmlValidityErrorFunc>,     // Error callback
    pub warning: Option<xmlValidityWarningFunc>, // Warning callback
    pub node: *mut _xmlNode,                     // Current parsed Node
    pub nodeNr: c_int,                           // Depth of the parsing stack
    pub nodeMax: c_int,                          // Max depth
    pub nodeTab: *mut *mut _xmlNode,             // Array of nodes
    pub flags: c_uint,                           // Internal flags
    pub doc: *mut _xmlDoc,                       // The document
    pub valid: c_int,                            // Temporary validity check result
    pub vstate: *mut c_void,                     // Current validation state
    pub vstateNr: c_int,                         // Depth of validation stack
    pub vstateMax: c_int,                        // Max depth
    pub vstateTab: *mut c_void,                  // Array of validation states
    pub am: *mut c_void,                         // Automata
    pub state: *mut c_void,                      // Automata state
}

// ── xmlParserNodeInfo ───────────────────────────────────────────────────

/// Node info for parser tracking.
#[repr(C)]
pub struct _xmlParserNodeInfo {
    pub node: *const _xmlNode,
    pub begin_pos: c_ulong,
    pub begin_line: c_ulong,
    pub end_pos: c_ulong,
    pub end_line: c_ulong,
}

/// Node info sequence.
#[repr(C)]
pub struct _xmlParserNodeInfoSeq {
    pub block: *mut _xmlParserNodeInfo,
    pub index: *mut c_int,
    pub block_max: c_int,
    pub size: c_int,
}

/// Typedef alias for `_xmlParserNodeInfoSeq`.
pub type xmlParserNodeInfoSeq = _xmlParserNodeInfoSeq;

// ── xmlXPathContext ─────────────────────────────────────────────────────
//
// Source: xpath.h

/// XPath evaluation context.
#[repr(C)]
pub struct _xmlXPathContext {
    pub doc: *mut _xmlDoc,                                 // The current document
    pub node: *mut _xmlNode,                               // The current node
    pub nb_variables_unused: c_int,                        // (unused)
    pub max_variables_unused: c_int,                       // (unused)
    pub varHash: *mut c_void,                              // Hash table of defined variables
    pub nb_types: c_int,                                   // Number of defined types
    pub max_types: c_int,                                  // Max number of types
    pub types: *mut c_void,                                // Array of defined types (xmlXPathType)
    pub nb_funcs_unused: c_int,                            // (unused)
    pub max_funcs_unused: c_int,                           // (unused)
    pub funcHash: *mut c_void,                             // Hash table of defined funcs
    pub nb_axis: c_int,                                    // Number of defined axis
    pub max_axis: c_int,                                   // Max number of axis
    pub axis: *mut c_void,                                 // Array of defined axis (xmlXPathAxis)
    pub namespaces: *mut *mut _xmlNs,                      // Array of namespaces
    pub nsNr: c_int,                                       // Number of namespaces in scope
    pub user: *mut c_void,                                 // Function to free
    pub contextSize: c_int,                                // Context size
    pub proximityPosition: c_int,                          // Proximity position
    pub xptr: c_int,                                       // XPointer context?
    pub here: *mut _xmlNode,                               // For here()
    pub origin: *mut _xmlNode,                             // For origin()
    pub nsHash: *mut c_void,                               // Namespaces hash table
    pub varLookupFunc: Option<xmlXPathVariableLookupFunc>, // Variable lookup func
    pub varLookupData: *mut c_void,                        // Variable lookup data
    pub extra: *mut c_void,                                // Needed for XSLT
    pub function: *const xmlChar,                          // Function name when calling a function
    pub functionURI: *const xmlChar,                       // Function namespace URI
    pub funcLookupFunc: Option<xmlXPathFuncLookupFunc>,    // Function lookup func
    pub funcLookupData: *mut c_void,                       // Function lookup data
    pub tmpNsList: *mut *mut _xmlNs,                       // Array of temp namespaces
    pub tmpNsNr: c_int,                                    // Number of temp namespaces
    pub userData: *mut c_void,                             // User specific data
    pub error: Option<xmlStructuredErrorFunc>,             // Error callback
    pub lastError: _xmlError,                              // Last error
    pub debugNode: *mut _xmlNode,                          // Source node (XSLT)
    pub dict: *mut c_void,                                 // Dictionary
    pub flags: c_int,                                      // Compilation flags
    pub cache: *mut c_void,                                // Cache for XPath objects
    pub opLimit: c_ulong,                                  // Resource limits
    pub opCount: c_ulong,
    pub depth: c_int,
}

// ── xmlXPathObject ──────────────────────────────────────────────────────
//
// Source: xpath.h

/// XPath evaluated object.
#[repr(C)]
pub struct _xmlXPathObject {
    pub type_: c_int,            // Object type
    pub nodesetval: *mut c_void, // Node set (xmlNodeSet)
    pub boolval: c_int,          // Boolean value
    pub floatval: f64,           // Number value
    pub stringval: *mut xmlChar, // String value
    pub user: *mut c_void,       // User pointer
    pub index: c_int,            // Index
    pub user2: *mut c_void,      // User pointer 2
    pub index2: c_int,           // Index 2
}

// ── Node set (contained within XPath objects) ───────────────────────────

/// XPath node set.
#[repr(C)]
pub struct _xmlNodeSet {
    pub nodeNr: c_int,               // Number of nodes
    pub nodeMax: c_int,              // Max number of nodes
    pub nodeTab: *mut *mut _xmlNode, // Array of nodes
}

// ── XSLT types ──────────────────────────────────────────────────────────
//
// Source: xslt.h, xsltInternals.h (from libxslt)

/// XSLT stylesheet (opaque, forward declaration).
#[repr(C)]
pub struct _xsltStylesheet {
    // Filled in when libxslt module is implemented (Phase 8)
    _unused: [u8; 0],
}

/// XSLT transform context (opaque, forward declaration).
#[repr(C)]
pub struct _xsltTransformContext {
    // Filled in when libxslt module is implemented (Phase 8)
    _unused: [u8; 0],
}

// ── Type aliases for pointer types ──────────────────────────────────────

pub type xmlNodePtr = *mut _xmlNode;
pub type xmlDocPtr = *mut _xmlDoc;
pub type xmlNsPtr = *mut _xmlNs;
pub type xmlAttrPtr = *mut _xmlAttr;
pub type xmlDtdPtr = *mut _xmlDtd;
pub type xmlEntityPtr = *mut _xmlEntity;
pub type xmlErrorPtr = *mut _xmlError;
pub type xmlParserCtxtPtr = *mut _xmlParserCtxt;
pub type xmlParserInputPtr = *mut _xmlParserInput;
pub type xmlParserInputBufferPtr = *mut _xmlParserInputBuffer;
pub type xmlOutputBufferPtr = *mut _xmlOutputBuffer;
pub type xmlSAXHandlerPtr = *mut _xmlSAXHandler;
pub type xmlValidCtxtPtr = *mut _xmlValidCtxt;
pub type xmlBufferPtr = *mut _xmlBuffer;
pub type xmlXPathContextPtr = *mut _xmlXPathContext;
pub type xmlXPathObjectPtr = *mut _xmlXPathObject;
pub type xmlNodeSetPtr = *mut _xmlNodeSet;
pub type xmlCharEncodingHandlerPtr = *mut _xmlCharEncodingHandler;
pub type xmlBufPtr = *mut _xmlBuf;
pub type xsltStylesheetPtr = *mut _xsltStylesheet;
pub type xsltTransformContextPtr = *mut _xsltTransformContext;