Expand description
SAX-driven arena DOM parser.
Produces a sup_xml_tree::dom::Document by feeding [XmlReader]
events into a DocumentBuilder. Compared to the existing
parse_str / parse_bytes DOM
parsers — which build a per-node-heap-allocated tree — this version
allocates the entire tree in a single bumpalo::Bump. Per-node alloc
cost drops to a pointer bump; drop is free per node.
§Why a separate entry point
The arena DOM has a different type ([arena::Document]) than the legacy
tree. We expose this as a parallel API so consumers can migrate one at a
time. Once everything’s ported, the legacy entry points can become thin
wrappers (or get deleted).
§Implementation
Wraps [XmlReader] — the SAX layer. All XML correctness (well-formedness
checks, entity expansion, encoding handling, recovery mode) comes from the
reader. This module is pure tree assembly: pop/push elements on a stack,
attach leaf nodes to the current top, copy strings into the arena.
§Example
use sup_xml_core::{parse_str, ParseOptions};
let doc = parse_str("<r><a id='1'/></r>", &ParseOptions::default()).unwrap();
let root = doc.root();
assert_eq!(root.name(), "r");
let a = root.children().next().unwrap();
assert_eq!(a.name(), "a");
assert_eq!(a.attributes().next().unwrap().value(), "1");Functions§
- parse_
bytes - Byte-slice sibling of
parse_str. - parse_
bytes_ in_ place - Destructive-parse fast path. Takes ownership of
buf, mutates it in place during parsing, and returns aDocumentwhose strings point directly into the (now-mutated) buffer. The Document keeps the buffer alive for its lifetime. - parse_
bytes_ ⚠unchecked - Byte-slice version that skips the upfront UTF-8 validation. Mirrors
parse_bytes_unchecked. - parse_
bytes_ with_ dtd - Variant of
parse_bytesthat also returns the DTD captured from the internal subset. Returns an emptyDtdwhen the document had no<!DOCTYPE … [ … ]>or no<!ELEMENT>/<!ATTLIST>declarations. - parse_
bytes_ ⚠with_ dtd_ and_ dict - Variant of
parse_bytes_with_dtdthat interns names through a caller-supplied refcounted dict instead of an internal one. Use when the resulting document needs to share name canonicals with another consumer that owns the same dict (e.g. a C-ABI parser context whosectxt->dictalready points to a thread- shared interner). - parse_
bytes_ ⚠with_ dtd_ dict_ arena - Variant of
parse_bytes_with_dtd_and_dictthat also adopts an externally-supplied [Bump] arena (shared viaArc). Used by C-ABI consumers that route every per-thread parse through a single shared arena — node memory then outlives any individual document and cross-doc graft operations are safe by construction. - parse_
bytes_ with_ recovered - Recovery-mode sibling of
parse_bytes. Seeparse_str_with_recoveredfor semantics. - parse_
external_ subset - Parse a standalone external DTD subset into a
Dtd. - parse_
ns_ bytes - Byte-slice sibling of
parse_ns_str. Validates UTF-8 (or auto-transcodes ifauto_transcodeis on) before parsing. - parse_
ns_ str - Parse
inputwith XML Namespaces 1.0 processing enabled — resolvesxmlnsdeclarations, fills thenamespacefield on every element and prefixed attribute, validates QName syntax, and rejects undeclared prefixes. Convenience wrapper overparse_strwithnamespace_aware: true. - parse_
str - Parse
inputinto an arena-allocatedDocument. Uses defaultParseOptions. - parse_
str_ with_ recovered - Recovery-mode sibling of
parse_str. Returns the (best-effort) parsedDocumentalong with the list of non-fatal errors that recovery mode forgave. WhenParseOptions::recovery_modeisfalsethe second element is always empty and the first is the sameResultasparse_strwould have produced.