|
Arduino DLNA Server
|
Lightweight streaming XML parser. More...
#include <XMLParser.h>

Public Member Functions | |
| XMLParser ()=default | |
| XMLParser (const char *xmlStr, void(*callback)(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref), bool textOnly=false) | |
| Construct with XML buffer and callback. | |
| void | setReference (void *ref) |
| Attach an opaque user pointer to the parser instance. | |
| void | setXml (const char *xmlStr) |
| Set the XML buffer to parse. | |
| void | setCallback (void(*cb)(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref)) |
| Set the callback to be invoked for parsed fragments. | |
| void | parse () |
| Parse the previously set XML buffer and invoke the callback. | |
| bool | parseSingle () |
| Parse a single fragment (one callback invocation) from the previously set XML buffer. | |
| void | resetParse () |
| Reset the internal parse position so subsequent parseSingle() calls start from the beginning of the buffer. | |
| void | resetParser () |
| Fully reset parser state (parse position, path stack and content starts). Use this when the underlying buffer has been trimmed/changed so the parser's internal stacks do not retain state from the previous buffer view. | |
| void | setReportTextOnly (bool flag) |
| report only nodes with text | |
| int | getParsePos () |
| Expose current parse position for incremental wrappers. | |
Protected Member Functions | |
| int | findGt (const char *s, int start, int len) |
| void | emitTextSegment (const char *s, int ts, int te) |
| void | emitTagSegment (const char *s, int lt, int gt) |
| int | handleEndTag (const char *s, int lt, int gt) |
| void | handleStartTag (const char *s, int lt, int gt) |
| int | handleCommentOrPI (int lt, const char *s, int len) |
| bool | invokeCallback (Str &nodeName, Vector< Str > &fullPath, Str &text, Str &attributes, int start, int len) |
| void | do_parse () |
| bool | do_parse_single () |
Protected Attributes | |
| StrView | str_view |
| Vector< Str > | path {5} |
| Str | empty_str {0} |
| Str | node_name {40} |
| Str | txt {100} |
| Str | str {100} |
| Str | last_attributes |
| bool | report_text_only = true |
| void(* | callback )(Str &nodeName, Vector< Str > &path, Str &text, Str &attributes, int start, int len, void *ref) = nullptr |
| Vector< int > | contentStarts |
| void * | reference = nullptr |
| int | parsePos = 0 |
Lightweight streaming XML parser.
XMLParser performs a single-pass, forgiving parse of a provided XML buffer and calls a user-provided callback for discovered fragments. It is intentionally small and suitable for embedded use-cases in this project (SCPD fragments, DIDL snippets, etc.). It does not implement the full XML specification (no DTDs, no entity decoding, minimal attribute handling).
The callback receives both a small copied Str for convenience and the numeric start/length offsets into the original buffer so callers can avoid additional copies when desired.
Threading / lifetime notes:
|
default |
Default constructor. Use setXml() and setCallback() before parse().
|
inline |
Construct with XML buffer and callback.
| xmlStr | Null-terminated XML buffer. The buffer is not copied; it must remain valid for the duration of parse(). |
| callback | Function pointer invoked for node events. Signature: void callback(const Str& nodeName, const Vector<Str>& path, const Str&
text, int start, int len, void* ref)
|
| textOnly | If true, only report nodes with text content. |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
Expose current parse position for incremental wrappers.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
|
inline |
Parse a single fragment (one callback invocation) from the previously set XML buffer.
This allows incremental parsing of a larger buffer by repeatedly calling parseSingle() until it returns false. The parser will resume from the last position between calls. Call resetParse() to start parsing from the beginning again.
|
inline |
Reset the internal parse position so subsequent parseSingle() calls start from the beginning of the buffer.
|
inline |
Fully reset parser state (parse position, path stack and content starts). Use this when the underlying buffer has been trimmed/changed so the parser's internal stacks do not retain state from the previous buffer view.
|
inline |
Set the callback to be invoked for parsed fragments.
| cb | Function pointer with signature described in the constructor docs. |
|
inline |
Attach an opaque user pointer to the parser instance.
| ref | Arbitrary user data. The parser does not own or manipulate this pointer; it is provided for callbacks or external use. |
|
inline |
report only nodes with text
|
inline |
Set the XML buffer to parse.
| xmlStr | Null-terminated XML buffer. The parser stores a non-owning view — the buffer must remain valid until parsing finishes. |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |