ddn.data.xml.sax

SAX-style (push) parsing API.

This module provides a handler/callback parsing surface inspired by libxml2's SAX2 interface.

Note

This is a minimal initial implementation. It is designed to be extended (namespaces, DTD events,

entity callbacks, richer error reporting).

Types 4

An attribute delivered to XmlSaxHandler.startElement.

Fields
string nameAttribute QName as it appeared in the source (e.g. `"id"` or `"p:href"`).
string valueAttribute value (decoded and normalized).

SAX parser options.

Fields
bool recoverIf `true`, attempt best-effort parsing on malformed input.
bool forbidDoctypeIf `true`, reject DOCTYPE.
bool expandEntitiesIf `true`, decode entity references in text/attribute values.
bool preserveWhitespaceIf `false`, ignore whitespace-only text nodes.
size_t maxExpandedBytesMaximum expanded bytes (safety). `0` means default.
size_t maxExpansionDepthMaximum entity expansion depth (safety). `0` means default.
interfaceXmlSaxHandler

Handler interface for SAX-style parsing.

Methods
void startElement(string name, const(XmlSaxAttribute)[] attributes, XmlLocation location) @safeCalled on a start element.
void endElement(string name, XmlLocation location) @safeCalled on an end element.
void text(string value, XmlLocation location) @safeCalled on character data.
void comment(string value, XmlLocation location) @safeCalled on comments.
void processingInstruction(string target, string data, XmlLocation location) @safeCalled on processing instructions.
void cdata(string value, XmlLocation location) @safeCalled on CDATA sections.
void doctype(string raw, XmlLocation location) @safeCalled on DOCTYPE declarations (raw text as returned by lexer).

An incremental (streaming) SAX-style XML parser that accepts data in chunks.

This class wraps an XmlIncrementalReader and dispatches events to an XmlSaxHandler as they become available. The caller drives the pump loop explicitly:

auto parser = new XmlIncrementalSaxParser(handler);
parser.feed("<root>");
parser.pump();
parser.feed("<child/></root>");
parser.markEndOfStream();
parser.pump();

Ownership: All strings passed to handler callbacks are owned storage

and remain valid until the parser is destroyed.

Status model: Delegates to the underlying XmlIncrementalReader status.
Fields
private XmlIncrementalReader _reader
private XmlSaxHandler _handler
private XmlSaxOptions _options
private bool _sawRoot
Methods
void feed(const(char)[] chunk) @safeAppends `chunk` to the internal unread buffer.
void markEndOfStream() @safe pure nothrowSignals that no more data will be fed.
XmlStreamStatus status() const @safe pure nothrowReturns the current underlying reader status.
void compact() @safe pure nothrowMoves unread bytes to the front of the internal buffer to reclaim space.
XmlStreamStatus pump() @safePumps the parser, dispatching zero or more events to the handler.
private void dispatchStartElement(const ref XmlEvent ev) @safeDispatches a start-element event to the handler.
Constructors
this(XmlSaxHandler handler, string systemId = "", XmlSaxOptions options = XmlSaxOptions.init, XmlIncrementalReaderOptions readerOptions = XmlIncrementalReaderOptions.init)Constructs an incremental SAX parser.

Functions 3

fnvoid parseSax(string input, XmlSaxHandler handler, XmlSaxOptions options = XmlSaxOptions.init, string systemId = "") @safeParses `input` and drives `handler` callbacks.
fnvoid parseSax( const(ubyte)[] input, XmlSaxHandler handler, XmlSaxOptions options = XmlSaxOptions.init, string systemId = "") @safeParses XML from bytes, decoding UTF-8/UTF-16 to UTF-8, then drives SAX callbacks.
private fnvoid validateXmlChars(string text, XmlVersion xmlVersion, XmlLocation loc) @safe