entity callbacks, richer error reporting).
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,
class XmlIncrementalSaxParser
iface XmlSaxHandler
Types 4
structXmlSaxAttribute
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).structXmlSaxOptions
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 processingInstruction(string target, string data, XmlLocation location) @safeCalled on processing instructions.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 underlyingXmlIncrementalReader status.Fields
private XmlIncrementalReader _readerprivate XmlSaxHandler _handlerprivate XmlSaxOptions _optionsprivate bool _sawRootMethods
void compact() @safe pure nothrowMoves unread bytes to the front of the internal buffer to reclaim space.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
fn
void parseSax(string input, XmlSaxHandler handler, XmlSaxOptions options = XmlSaxOptions.init, string systemId = "") @safeParses `input` and drives `handler` callbacks.fn
void 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.