Small utility to extract attributes from a start-tag in an XML fragment.
More...
#include <XMLAttributeParser.h>
|
| 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 | extractAttribute (const char *attrs, const char *attrName, char *outBuf, size_t bufSize) |
| | Extract an attribute value directly from an attributes string.
|
| |
| static bool | extractQuotedValue (const char *attrPos, const char *boundary, char *outBuf, size_t bufSize) |
| |
| 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.
|
| |
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).
◆ extractAttribute() [1/2]
| static bool tiny_dlna::XMLAttributeParser::extractAttribute |
( |
const char * |
attrs, |
|
|
const char * |
attrName, |
|
|
char * |
outBuf, |
|
|
size_t |
bufSize |
|
) |
| |
|
inlinestatic |
Extract an attribute value directly from an attributes string.
This is a lightweight helper that searches attrs for attrName and extracts the double-quoted value that follows. Use this when you already have the contents of a start-tag (everything between '<tag' and '>') and don't want to search for a tag name first.
- Parameters
-
| attrs | Null-terminated string containing attributes (e.g. protocolInfo="http-get:*:audio/mpeg:*" other="..."). |
| attrName | Name of the attribute to find (with or without trailing '='). Example: "protocolInfo" or "protocolInfo=". |
| outBuf | Destination buffer for the attribute value (null-terminated). |
| bufSize | Size of outBuf in bytes. |
- Returns
- true if a non-empty value was found and written into outBuf.
◆ extractAttribute() [2/2]
| 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
-
| xml | Pointer to a null-terminated XML fragment to search. |
| tagName | Start-tag to locate (e.g. "<res"). |
| attrName | Attribute name to extract (e.g. "protocolInfo" or "protocolInfo="). The function expects a double-quoted value (attrName="..."). |
| outBuf | Destination buffer where the extracted value will be written (null-terminated). Must be non-null. |
| bufSize | Size 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
-
| xml | Pointer to a null-terminated XML fragment to search. |
| tagName | Start-tag to locate (e.g. "<res"). Only the first occurrence is scanned. |
| attrName | Attribute name to extract (with or without trailing '='). The function expects a double-quoted value. |
| n | 1-based index of the colon-separated token to return. |
| outBuf | Destination buffer where the token will be written (null-terminated). Must be non-null. |
| bufSize | Size 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".
◆ extractQuotedValue()
| static bool tiny_dlna::XMLAttributeParser::extractQuotedValue |
( |
const char * |
attrPos, |
|
|
const char * |
boundary, |
|
|
char * |
outBuf, |
|
|
size_t |
bufSize |
|
) |
| |
|
inlinestatic |
The documentation for this class was generated from the following file: