Arduino DLNA Server
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
tiny_dlna::XMLAttributeParser Class Reference

Small utility to extract attributes from a start-tag in an XML fragment. More...

#include <XMLAttributeParser.h>

Static Public Member Functions

static bool extractAttribute (const char *xml, const char *tagName, const char *attrName, char *outBuf, size_t bufSize)
 Find the first occurrence of a start-tag and extract an attribute value.
 
static bool extractAttributeToken (const char *xml, const char *tagName, const char *attrName, int n, char *outBuf, size_t bufSize)
 Extract the nth (1-based) colon-separated token from an attribute value located on the first occurrence of tagName.
 

Detailed Description

Small utility to extract attributes from a start-tag in an XML fragment.

This helper does not attempt full XML validation but is suitable for small embedded parsing tasks (for example: extracting the protocolInfo attribute from a DIDL-Lite <res ...> element).

Member Function Documentation

◆ extractAttribute()

static bool tiny_dlna::XMLAttributeParser::extractAttribute ( const char *  xml,
const char *  tagName,
const char *  attrName,
char *  outBuf,
size_t  bufSize 
)
inlinestatic

Find the first occurrence of a start-tag and extract an attribute value.

This searches for the first occurrence of tagName (for example "<res") in xml and looks for the attribute named attrName inside that tag. If found, the attribute value (the text between the surrounding double quotes) is copied into outBuf (null-terminated).

Parameters
xmlPointer to a null-terminated XML fragment to search.
tagNameStart-tag to locate (e.g. "<res").
attrNameAttribute name to extract (e.g. "protocolInfo" or "protocolInfo="). The function expects a double-quoted value (attrName="...").
outBufDestination buffer where the extracted value will be written (null-terminated). Must be non-null.
bufSizeSize of outBuf in bytes; if the attribute value is longer than bufSize - 1 it will be truncated.
Returns
true if a non-empty attribute value was found and written into outBuf, false otherwise (invalid inputs, tag/attribute not found, malformed tag).

◆ extractAttributeToken()

static bool tiny_dlna::XMLAttributeParser::extractAttributeToken ( const char *  xml,
const char *  tagName,
const char *  attrName,
int  n,
char *  outBuf,
size_t  bufSize 
)
inlinestatic

Extract the nth (1-based) colon-separated token from an attribute value located on the first occurrence of tagName.

This helper locates tagName (for example "<res") and extracts the value of attrName (expects a double-quoted value). The attribute value is split on ':' characters and the nth token (1-based) is copied into outBuf.

Parameters
xmlPointer to a null-terminated XML fragment to search.
tagNameStart-tag to locate (e.g. "<res"). Only the first occurrence is scanned.
attrNameAttribute name to extract (with or without trailing '='). The function expects a double-quoted value.
n1-based index of the colon-separated token to return.
outBufDestination buffer where the token will be written (null-terminated). Must be non-null.
bufSizeSize of outBuf in bytes; if the token is longer than bufSize - 1 it will be truncated.
Returns
true if the requested token was found and written into outBuf, false otherwise (invalid inputs, tag/attribute not found, index out of range).

Example: attrName = "protocolInfo" (or "protocolInfo="), n = 3 protocolInfo="http-get:*:audio/mpeg:*" -> returns "audio/mpeg".


The documentation for this class was generated from the following file: