ddn.data.xml.stream

Streaming (pull) parsing and event model entrypoints.

Types 5

Status codes for the incremental streaming reader (XmlIncrementalReader).

The reader is always in exactly one of these states:

  • NEED_MORE_DATA — no event is available; the caller must feed() more bytes.
  • READY — an event is available via front().
  • END_OF_STREAMmarkEndOfStream() was called and all input has been consumed.

END_OF_STREAM is terminal: once entered, no further operation changes the status. READY is transient: a subsequent advance() transitions to one of the other states.

NEED_MORE_DATANo event available; caller must `feed()` more bytes.
READYAn event is available via `front()`.
END_OF_STREAM`markEndOfStream()` was called and all input has been consumed.

Options controlling XmlReader behavior.

Fields
bool substituteEntitiesIf `true`, decode entity references in text and attribute values.
bool forbidDoctypeIf `true`, reject `DOCTYPE` declarations.

A pull-style streaming XML reader.

The reader is an input range over XmlEvent.

Fields
private XmlLexer _lexer
private XmlParserLimits _limits
private XmlEvent _front
private bool _empty
private XmlReaderOptions _options
private TokenProcessingState _state
private size_t _attributeIndex
Methods
bool empty() @property const @safe nothrowReturns `true` when the reader reached end-of-input.
const(XmlEvent) front() @property ref const @safe nothrowReturns the current event.
XmlReader save() @property @safeSaves the current state of the reader.
void popFront() @safeAdvances to the next event.
size_t depth() @property const @safe nothrowReturns the current reader depth.
bool isEmptyElement() @property const @safe nothrowReturns `true` if the current event is a `START_ELEMENT` for an empty element.
bool onAttribute() @property const @safe nothrowReturns `true` if the reader is positioned on an attribute of the current `START_ELEMENT`.
bool moveToFirstAttribute() @safe nothrowMoves to the first attribute on the current `START_ELEMENT`.
bool moveToNextAttribute() @safe nothrowMoves to the next attribute.
void moveToElement() @safe nothrowMoves back to the element from attribute position.
string readString() @safeReturns the string value of the current event's content. If on STARTELEMENT, it reads until matching ENDELEMENT and returns concatenated text.
long readLong() @safeReads the current element content as a long.
double readDouble() @safeReads the current element content as a double.
bool readBool() @safeReads the current element content as a boolean.
string readInnerXml() @safeReads the inner XML content of the current element.
string readOuterXml() @safeReads the current element and its content as XML.
void writeEvent(XmlStreamWriter writer, ref const(XmlEvent) ev) @safe
const(XmlEventAttribute) attribute() @property ref const @safe nothrowReturns the current attribute.
string name() @property const @safe nothrowReturns the current node name (`prefix:local` or `local`).
string prefix() @property const @safe nothrowReturns the current node prefix.
string local() @property const @safe nothrowReturns the current node local name.
string namespaceUri() @property const @safe nothrowReturns the current node namespace URI.
size_t attributeCount() @property const @safe nothrowReturns the attribute count for the current `START_ELEMENT`.
string getAttribute(string qname) const @safe nothrowLooks up an attribute value by lexical name.
string getAttributeNS(string uri, string localName) const @safe nothrowLooks up an attribute value by expanded name `{namespaceUri, local}`.
bool moveToAttributeNS(string uri, string localName) @safe nothrowMoves to an attribute by expanded name `{namespaceUri, local}`.
void advance() @safe
Constructors
this( string input, string systemId = "", size_t maxExpandedBytes = 0, XmlReaderOptions options = XmlReaderOptions.init)Constructs a reader over `input`.

Options controlling XmlIncrementalReader behavior.

Fields
bool substituteEntitiesIf `true`, decode entity references in text and attribute values.
bool forbidDoctypeIf `true`, reject `DOCTYPE` declarations.

An incremental (streaming) pull-style XML reader that accepts data in chunks.

Unlike XmlReader, which requires the entire XML input up front, this reader maintains an internal growable buffer and supports the feed() / compact() / markEndOfStream() lifecycle required for streaming parsing.

The reader operates as an explicit pump loop:

auto reader = new XmlIncrementalReader();
while (reader.status() == XmlStreamStatus.NEED_MORE_DATA) {
   auto chunk = socket.receive(buffer[]);
   if (chunk.length == 0) { reader.markEndOfStream(); break; }
   reader.feed(chunk);
   while (reader.advance() == XmlStreamStatus.READY) {
       processEvent(reader.front());
   }
}

Ownership: Every string field in XmlEvent and its sub-fields is owned

storage, not a slice into the internal buffer. Event strings remain valid until the reader is destroyed. compact() and feed() do not invalidate previously returned event strings.

Status model:
  • NEED_MORE_DATA — no event available; caller must feed() more bytes.
  • READY — an event is available via front().
  • END_OF_STREAM — terminal; markEndOfStream() was called and all input

has been consumed.

ForwardRange / save() are explicitly excluded from the initial release.

Fields
private XmlIncrementalLexer _lexer
private XmlParserLimits _limits
private XmlEvent _front
private XmlStreamStatus _status
private bool _eos
private TokenProcessingState _state
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 reader status.
bool ready() const @safe pure nothrowReturns `true` when an event is available via `front()`.
const(XmlEvent) front() ref const @safe nothrowReturns the current event.
XmlStreamStatus advance() @safeAttempts to produce the next event.
void compact() @safe pure nothrowMoves unread bytes to the front of the internal buffer to reclaim space.
size_t depth() @property const @safe nothrowReturns the current reader depth.
bool isEmptyElement() @property const @safe nothrowReturns `true` if the current event is a `START_ELEMENT` for an empty element.
Constructors
this(string systemId = "", XmlIncrementalReaderOptions options = XmlIncrementalReaderOptions.init)Constructs an incremental reader.