XML Parser for tiny systems. More...
Defines | |
#define | MAX_UXMLTAG_SIZE 512 |
Maximum tag size including brackets. | |
#define | MAX_UXMLTKN_SIZE 64 |
Maximum token size. | |
Functions | |
char * | UxmlParseTag (char *data, char *tkn, size_t size) |
Retrieve the next token from an XML tag. | |
int | UxmlFilterMatch (char *name, char **filt) |
Check if name matches filter list. | |
UXML_NODE * | UxmlParseStream (FILE *stream, char **f_tags, char **f_attr) |
Parse XML stream. | |
UXML_NODE * | UxmlNodeCreate (char *name) |
Allocate a new tree node. | |
int | UxmlNodeAddAttrib (UXML_NODE *node, char *name, char *value) |
Add an attribute to the specified node. | |
UXML_NODE * | UxmlTreeAddSibling (UXML_NODE *node, UXML_NODE *sibling) |
Add a sibling to the specified node. | |
UXML_NODE * | UxmlTreeAddChild (UXML_NODE *node, UXML_NODE *child) |
Add a child to the specified node. | |
void | UxmlTreeDestroy (UXML_NODE *node) |
Release all memory of an XML tree structure. |
XML Parser for tiny systems.
#define MAX_UXMLTAG_SIZE 512 |
Maximum tag size including brackets.
Larger tags will be silently discarded.
Referenced by UxmlParseStream().
#define MAX_UXMLTKN_SIZE 64 |
Maximum token size.
Larger tokens will be cut to the specified size. This may be fine for attribute values containing lengthy descriptions, but may be disastrous for tag or attribute names.
Referenced by UxmlParseStream().
char* UxmlParseTag | ( | char * | data, |
char * | tkn, | ||
size_t | size | ||
) |
Retrieve the next token from an XML tag.
data | Pointer to the next character within the string to parse. |
tkn | Pointer to the buffer that receives the next token. |
size | Size of the token buffer. |
Referenced by UxmlParseStream().
int UxmlFilterMatch | ( | char * | name, |
char ** | filt | ||
) |
Check if name matches filter list.
name | String to check against list. |
filt | Array of filter strings. |
References NULL, and strcasecmp.
Referenced by UxmlParseStream().
Parse XML stream.
This is the main routine of the Micro XML Stream Parser. It reads the XML document from a previously opened stream and creates a corresponding tree structure.
Note, that this is a minimal and probably incomplete implementation, which had been specifically created to parse the SHOUTcast radio station list. On the other hand, it offers a practical XML parser solution for embedded systems with very low memory resources. Unlike most other implementations, it does not require to copy the whole XML document into internal memory. Instead, the parser reads and interprets individual tags. Furthermore, the caller may specify tag and attribute filters to reduce the resulting tree size. Be aware, that because of filtering the root of the tree may have siblings.
Normally the parser will return when the end of a file is reached. On TCP connections this may be either on connection close or timeout. If closing and re-opening connections may create too much overhead and timeouts are too slow, an EOF (ASCII 0) may be sent alternatively.
stream | The stream to read from. |
f_tags | Optional tag filter, which points to an array of tag names to include. All other tags will be discarded. This can be used to limit memory consumption of the tree structure. Note, that this filtering may result in a tree structure, which is different from the structure of the original document. Set to NULL to disable tag filtering. |
f_attr | Optional attribute filter, which points to an array of attribute names to include. All other attributes will be discarded. Like the tag filter, it can be used to limit memory consumption of the tree structure. Set to NULL to disable attribute filtering. |
References free(), malloc(), MAX_UXMLTAG_SIZE, MAX_UXMLTKN_SIZE, NULL, NutHeapAvailable, strcasecmp, strdup(), strlen(), UxmlFilterMatch(), UxmlNodeAddAttrib(), UxmlNodeCreate(), UxmlParseTag(), UxmlTreeAddChild(), UxmlTreeAddSibling(), _UXML_NODE::xmln_name, and _UXML_NODE::xmln_parent.
UXML_NODE* UxmlNodeCreate | ( | char * | name | ) |
Allocate a new tree node.
name | Name of the node to add. |
References malloc(), memcpy(), memset(), NULL, strlen(), and _UXML_NODE::xmln_name.
Referenced by UxmlParseStream().
int UxmlNodeAddAttrib | ( | UXML_NODE * | node, |
char * | name, | ||
char * | value | ||
) |
Add an attribute to the specified node.
node | The attribute is added to this node. |
name | Attribute's name. |
value | Attribute's value. |
References attr, free(), malloc(), NULL, strdup(), _UXML_ATTRIB::xmla_name, _UXML_ATTRIB::xmla_next, _UXML_ATTRIB::xmla_value, and _UXML_NODE::xmln_attribs.
Referenced by UxmlParseStream().
Add a sibling to the specified node.
node | The sibling is added to this node. |
child | Sibling to add. |
References NULL, _UXML_NODE::xmln_next, and _UXML_NODE::xmln_parent.
Referenced by UxmlParseStream(), and UxmlTreeAddChild().
Add a child to the specified node.
node | The child is added to this node. |
child | Child to add. |
References NULL, UxmlTreeAddSibling(), _UXML_NODE::xmln_child, and _UXML_NODE::xmln_parent.
Referenced by UxmlParseStream().
void UxmlTreeDestroy | ( | UXML_NODE * | node | ) |
Release all memory of an XML tree structure.
node | Pointer to the root entry. |
References UxmlTreeDestroy(), _UXML_NODE::xmln_child, and _UXML_NODE::xmln_next.
Referenced by UxmlTreeDestroy().