Skip to main content

Module parser

Module parser 

Source
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 a Document whose 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_bytes that also returns the DTD captured from the internal subset. Returns an empty Dtd when the document had no <!DOCTYPE … [ … ]> or no <!ELEMENT> / <!ATTLIST> declarations.
parse_bytes_with_dtd_and_dict
Variant of parse_bytes_with_dtd that 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 whose ctxt->dict already points to a thread- shared interner).
parse_bytes_with_dtd_dict_arena
Variant of parse_bytes_with_dtd_and_dict that also adopts an externally-supplied [Bump] arena (shared via Arc). 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. See parse_str_with_recovered for 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 if auto_transcode is on) before parsing.
parse_ns_str
Parse input with XML Namespaces 1.0 processing enabled — resolves xmlns declarations, fills the namespace field on every element and prefixed attribute, validates QName syntax, and rejects undeclared prefixes. Convenience wrapper over parse_str with namespace_aware: true.
parse_str
Parse input into an arena-allocated Document. Uses default ParseOptions.
parse_str_with_recovered
Recovery-mode sibling of parse_str. Returns the (best-effort) parsed Document along with the list of non-fatal errors that recovery mode forgave. When ParseOptions::recovery_mode is false the second element is always empty and the first is the same Result as parse_str would have produced.