Expand description
XmlBytesReader — bytes-typed streaming SAX-style API.
The byte-level parsing engine. Events carry Cow<'src, [u8]> payloads
sliced directly from the source — no UTF-8 cast at the emission
boundary. XmlReader is a thin wrapper
over this type that adds the &[u8] → &str conversion.
§Why two readers exist
Some callers prefer raw bytes — byte-literal tag matching
(name == b"item"), hash/digest pipelines, format conversion, byte
forwarding — and would rather not pay for the type system’s &str
guarantee. XmlBytesReader (this module) serves them. Most callers
want validated strings; XmlReader serves
them and is the recommended default. The two share a single parser;
the only difference is the payload type each emits.
§UTF-8 invariant
Bytes emitted here are still valid UTF-8 — the [Scanner] enforces
that at construction time (from_bytes validates; from_bytes_unchecked
documents the caller obligation). The bytes-typed API simply chooses
not to surface that fact through the type system, which is exactly
what lets the str-typed wrapper convert via from_utf8_unchecked for
free.
§When to choose which
Reach for XmlBytesReader when you want to compare against byte
literals, forward bytes to another sink, or feed a hash/digest
pipeline. Reach for XmlReader when you
want &str payloads — string formatting, regex, anything that wants
Unicode-typed input. Performance is identical; the choice is purely
about the payload type you’d rather work with.
Structs§
- Bytes
Attr - A single attribute from a start tag, with a zero-copy value when possible.
- Bytes
Attrs - Lazy iterator over the attributes of a start tag, yielding raw byte
payloads — see
BytesAttrfor the shape of each item. - BytesC
Data - A
<![CDATA[…]]>section. Always source-borrowed in practice (entity references inside CDATA aren’t expanded per spec). - Bytes
Comment - An XML comment (
<!-- ... -->). The payload is the text strictly between the delimiters. - Bytes
EndTag - An end-tag event (
</element>— or the synthetic close emitted after every self-closing<element/>). Holds the matched tag’s name as a source-borrowed slice. - Bytes
Entity Ref BytesEvent::EntityRefpayload — the entity name only. The literal source form&{name};is reconstructable by callers.- BytesPi
- A processing instruction (
<?target content?>). - Bytes
Start Tag - A start-tag event (
<element ...>or<element/>). - Bytes
Text - Character-data text between elements.
Cow::Borrowedfor the common case (no entity refs in the literal);Cow::Ownedonly when the parser had to expand&entity;references. - XmlBytes
Reader - XmlDecl
Info - Captured XML declaration fields (
<?xml version="…" encoding="…" standalone="…"?>). Populated byXmlBytesReaderduring prolog parsing; available viaXmlBytesReader::xml_declafter the first event has been read.
Enums§
- Bytes
Event - A streaming XML event with lazy access to its payload.
- Bytes
Event Into - A streaming XML event with attributes already parsed into a caller-owned buffer.
Functions§
- resolve_
uri - Resolve a SYSTEM literal to a filesystem path (joining against
base_url’s parent directory for relative literals), read the file, and return its bytes. Used by external general-entity loading; mirrors the path-resolution rule inXmlBytesReader::load_external_subset. - unescape_
bytes - Expand the five XML predefined entity references (
&,<,>,",') and numeric character references (&#NN;,&#xNN;) insides. Intended for callers usingParseOptions::skip_entity_expansionwho want to decode a specific text payload on demand.