XgUXML

Defines

#define MAX_UXMLTKN_SIZE   64
 Maximum tag size including brackets.

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_NODEUxmlParseStream (FILE *stream, char **f_tags, char **f_attr)
 Parse XML stream.
UXML_NODEUxmlNodeCreate (char *name)
 Allocate a new tree node.
int UxmlNodeAddAttrib (UXML_NODE *node, char *name, char *value)
 Add an attribute to the specified node.
UXML_NODEUxmlTreeAddSibling (UXML_NODE *node, UXML_NODE *sibling)
 Add a sibling to the specified node.
UXML_NODEUxmlTreeAddChild (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.

Define Documentation

#define MAX_UXMLTKN_SIZE   64

Maximum tag size including brackets.

Larger tags will be silently discarded.

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.

Definition at line 75 of file uxmlstream.c.

Referenced by UxmlParseStream().


Function Documentation

char* UxmlParseTag ( char *  data,
char *  tkn,
size_t  size 
)

Retrieve the next token from an XML tag.

Parameters:
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.
Returns:
Pointer to the character following the one parsed last.

Definition at line 63 of file uxmlparse.c.

Referenced by UxmlParseStream().

int UxmlFilterMatch ( char *  name,
char **  filt 
)

Check if name matches filter list.

Parameters:
name String to check against list.
filt Array of filter strings.
Returns:
1 if the name matches at list one filter string. Otherwise 0 is returned.

Definition at line 112 of file uxmlparse.c.

References strcasecmp.

Referenced by UxmlParseStream().

UXML_NODE* UxmlParseStream ( FILE stream,
char **  f_tags,
char **  f_attr 
)

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.

Parameters:
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.
Returns:
Pointer to a newly allocated UXML_NODE tree structure. NULL may be returned in case of an error. The caller should use UxmlTreeDestroy() to release the memory allocated by the tree.
Todo:
Empty element tags with a slash in front of the closing angle bracket are not yet supported.

Definition at line 195 of file uxmlstream.c.

References free, malloc, MAX_UXMLTKN_SIZE, NutHeapAvailable, strcasecmp, strdup(), 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.

Parameters:
name Name of the node to add.
Returns:
Pointer to the new node. In case of an error, NULL is returned.

Definition at line 63 of file uxmltree.c.

References malloc, memcpy(), memset(), 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.

Parameters:
node The attribute is added to this node.
name Attribute's name.
value Attribute's value.
Returns:
0 on success, -1 otherwise.

Definition at line 87 of file uxmltree.c.

References attr, malloc, memcpy(), strlen(), UXML_ATTRIB::xmla_name, UXML_ATTRIB::xmla_next, UXML_ATTRIB::xmla_value, and UXML_NODE::xmln_attribs.

Referenced by UxmlParseStream().

UXML_NODE* UxmlTreeAddSibling ( UXML_NODE node,
UXML_NODE sibling 
)

Add a sibling to the specified node.

Parameters:
node The sibling is added to this node.
child Sibling to add.
Returns:
Pointer to the sibling node.

Definition at line 152 of file uxmltree.c.

References UXML_NODE::xmln_next, and UXML_NODE::xmln_parent.

Referenced by UxmlParseStream(), and UxmlTreeAddChild().

UXML_NODE* UxmlTreeAddChild ( UXML_NODE node,
UXML_NODE child 
)

Add a child to the specified node.

Parameters:
node The child is added to this node.
child Child to add.
Returns:
Pointer to the child node.

Definition at line 173 of file uxmltree.c.

References 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.

Parameters:
node Pointer to the root entry.

Definition at line 189 of file uxmltree.c.

References UxmlTreeDestroy(), UXML_NODE::xmln_child, and UXML_NODE::xmln_next.

Referenced by UxmlTreeDestroy().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/