Skip to main content

Module xml_bytes_reader

Module xml_bytes_reader 

Source
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§

BytesAttr
A single attribute from a start tag, with a zero-copy value when possible.
BytesAttrs
Lazy iterator over the attributes of a start tag, yielding raw byte payloads — see BytesAttr for the shape of each item.
BytesCData
A <![CDATA[…]]> section. Always source-borrowed in practice (entity references inside CDATA aren’t expanded per spec).
BytesComment
An XML comment (<!-- ... -->). The payload is the text strictly between the delimiters.
BytesEndTag
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.
BytesEntityRef
BytesEvent::EntityRef payload — the entity name only. The literal source form &{name}; is reconstructable by callers.
BytesPi
A processing instruction (<?target content?>).
BytesStartTag
A start-tag event (<element ...> or <element/>).
BytesText
Character-data text between elements. Cow::Borrowed for the common case (no entity refs in the literal); Cow::Owned only when the parser had to expand &entity; references.
XmlBytesReader
XmlDeclInfo
Captured XML declaration fields (<?xml version="…" encoding="…" standalone="…"?>). Populated by XmlBytesReader during prolog parsing; available via XmlBytesReader::xml_decl after the first event has been read.

Enums§

BytesEvent
A streaming XML event with lazy access to its payload.
BytesEventInto
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 in XmlBytesReader::load_external_subset.
unescape_bytes
Expand the five XML predefined entity references (&amp;, &lt;, &gt;, &quot;, &apos;) and numeric character references (&#NN;, &#xNN;) inside s. Intended for callers using ParseOptions::skip_entity_expansion who want to decode a specific text payload on demand.