Tizen Native API
Simple_XML

Functions

Eina_Bool eina_simple_xml_parse (const char *buf, unsigned buflen, Eina_Bool strip, Eina_Simple_XML_Cb func, const void *data)
 Parse a section of XML string text.
const char * eina_simple_xml_tag_attributes_find (const char *buf, unsigned buflen)
 Given the contents of a tag, find where the attributes start.
Eina_Bool eina_simple_xml_attributes_parse (const char *buf, unsigned buflen, Eina_Simple_XML_Attribute_Cb func, const void *data)
 Given a buffer with xml attributes, parse them to key=value pairs.
Eina_Simple_XML_Attribute * eina_simple_xml_attribute_new (Eina_Simple_XML_Node_Tag *parent, const char *key, const char *value)
 Create (and append) new attribute to tag.
void eina_simple_xml_attribute_free (Eina_Simple_XML_Attribute *attr)
 Remove attribute from parent and delete it.
Eina_Simple_XML_Node_Tag * eina_simple_xml_node_tag_new (Eina_Simple_XML_Node_Tag *parent, const char *name)
 Create new tag. If parent is provided, it is automatically appended.
void eina_simple_xml_node_tag_free (Eina_Simple_XML_Node_Tag *tag)
Eina_Simple_XML_Node_Data * eina_simple_xml_node_data_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new data. If parent is provided, it is automatically appended.
void eina_simple_xml_node_data_free (Eina_Simple_XML_Node_Data *node)
 Remove data from parent and delete it.
Eina_Simple_XML_Node_CData * eina_simple_xml_node_cdata_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new cdata. If parent is provided, it is automatically appended.
void eina_simple_xml_node_cdata_free (Eina_Simple_XML_Node_Data *node)
 Remove cdata from parent and delete it.
Eina_Simple_XML_Node_Doctype_Childeina_simple_xml_node_doctype_child_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new doctype child. If parent is provided, it is automatically appended.
void eina_simple_xml_node_doctype_child_free (Eina_Simple_XML_Node_Data *node)
 Remove doctype child from parent and delete it.
Eina_Simple_XML_Node_Processing * eina_simple_xml_node_processing_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new processing. If parent is provided, it is automatically appended.
void eina_simple_xml_node_processing_free (Eina_Simple_XML_Node_Data *node)
 Remove processing from parent and delete it.
Eina_Simple_XML_Node_Doctype * eina_simple_xml_node_doctype_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new doctype. If parent is provided, it is automatically appended.
void eina_simple_xml_node_doctype_free (Eina_Simple_XML_Node_Data *node)
 Remove doctype from parent and delete it.
Eina_Simple_XML_Node_Comment * eina_simple_xml_node_comment_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length)
 Create new comment. If parent is provided, it is automatically appended.
void eina_simple_xml_node_comment_free (Eina_Simple_XML_Node_Data *node)
 Remove comment from parent and delete it.
Eina_Simple_XML_Node_Root * eina_simple_xml_node_load (const char *buf, unsigned buflen, Eina_Bool strip)
 Load a XML node tree based on the given string.
void eina_simple_xml_node_root_free (Eina_Simple_XML_Node_Root *root)
 Free node tree build with eina_simple_xml_node_load()
char * eina_simple_xml_node_dump (Eina_Simple_XML_Node *node, const char *indent)
 Converts the node tree under the given element to a XML string.

Typedefs

typedef struct
_Eina_Simple_XML_Node_Data 
Eina_Simple_XML_Node_Doctype_Child

Simplistic relaxed SAX-like XML parser.

This parser is far from being compliant with XML standard, but will do for most XMLs out there. If you know that your format is simple and will not vary in future with strange corner cases, then you can use it safely.

The parser is SAX like, that is, it will tokenize contents and call you back so you can take some action. No contents are allocated during this parser work and it's not recursive, so you can use it with a very large document without worries.

It will not validate the document anyhow, neither it will create a tree hierarchy. That's up to you.

Accordingly to XML, open tags may contain attributes. This parser will not tokenize this. If you want you can use eina_simple_xml_tag_attributes_find() and then eina_simple_xml_attributes_parse().

For more information, see this example.


Typedef Documentation

typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Doctype_Child
Since (EFL) :
1.8

Enumeration Type Documentation

Enumerator:
EINA_SIMPLE_XML_NODE_DOCTYPE_CHILD 
Since (EFL) :
1.8

a simple XML type.

Enumerator:
EINA_SIMPLE_XML_OPEN 

<tag attribute="value">

EINA_SIMPLE_XML_OPEN_EMPTY 

<tag attribute="value" />

EINA_SIMPLE_XML_CLOSE 

</tag>

EINA_SIMPLE_XML_DATA 

tag text data

EINA_SIMPLE_XML_CDATA 

<![CDATA[something]]>

EINA_SIMPLE_XML_ERROR 

error contents

EINA_SIMPLE_XML_PROCESSING 

<?xml ... ?> <?php .. ?>

EINA_SIMPLE_XML_DOCTYPE 

<!DOCTYPE html

EINA_SIMPLE_XML_COMMENT 

<!-- something -->

EINA_SIMPLE_XML_IGNORED 

whatever is ignored by parser, like whitespace

EINA_SIMPLE_XML_DOCTYPE_CHILD 

<!DOCTYPE_CHILD

Since (EFL) :
1.8

Function Documentation

void eina_simple_xml_attribute_free ( Eina_Simple_XML_Attribute *  attr)

Remove attribute from parent and delete it.

Since :
2.3
Parameters:
[in]attrattribute to release memory.
Eina_Simple_XML_Attribute* eina_simple_xml_attribute_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  key,
const char *  value 
)

Create (and append) new attribute to tag.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the attribute will be appended to attributes list.
[in]keyNull-terminated string. Must not be NULL.
[in]valueNull-terminated string. If NULL, the empty string will be used.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_attribute_free() or indirectly with eina_simple_xml_node_tag_free().
Eina_Bool eina_simple_xml_attributes_parse ( const char *  buf,
unsigned  buflen,
Eina_Simple_XML_Attribute_Cb  func,
const void *  data 
)

Given a buffer with xml attributes, parse them to key=value pairs.

Since :
2.3
Parameters:
[in]bufthe input string. May not contain \0 terminator.
[in]buflenthe input string size.
[in]funcwhat to call back while parse to do some action. The first parameter is the given user data, the second is the key (null-terminated) and the last is the value (null terminated). These strings should not be modified and reference is just valid until the function return.
[in]datadata to pass to the callback function.
Returns:
EINA_TRUE on success or EINA_FALSE if it was aborted by user or parsing error.
void eina_simple_xml_node_cdata_free ( Eina_Simple_XML_Node_Data *  node)

Remove cdata from parent and delete it.

Since :
2.3
Parameters:
[in]nodeto release memory.
Eina_Simple_XML_Node_CData* eina_simple_xml_node_cdata_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new cdata. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the cdata will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of content.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_cdata_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
void eina_simple_xml_node_comment_free ( Eina_Simple_XML_Node_Data *  node)

Remove comment from parent and delete it.

Since :
2.3
Parameters:
[in]nodecomment to release memory.
Eina_Simple_XML_Node_Comment* eina_simple_xml_node_comment_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new comment. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the comment will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of contents.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_comment_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
void eina_simple_xml_node_data_free ( Eina_Simple_XML_Node_Data *  node)

Remove data from parent and delete it.

Since :
2.3
Parameters:
[in]nodeto release memory.
Eina_Simple_XML_Node_Data* eina_simple_xml_node_data_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new data. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the data will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of contents.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_data_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
void eina_simple_xml_node_doctype_child_free ( Eina_Simple_XML_Node_Data *  node)

Remove doctype child from parent and delete it.

Since :
2.3
Parameters:
[in]nodeto release memory.
Since (EFL) :
1.8
Eina_Simple_XML_Node_Doctype_Child* eina_simple_xml_node_doctype_child_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new doctype child. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the doctype child will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of content.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_doctype_child_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
Since (EFL) :
1.8
void eina_simple_xml_node_doctype_free ( Eina_Simple_XML_Node_Data *  node)

Remove doctype from parent and delete it.

Since :
2.3
Parameters:
[in]nodedoctype to release memory.
Eina_Simple_XML_Node_Doctype* eina_simple_xml_node_doctype_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new doctype. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the doctype will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of contents.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_doctype_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
char* eina_simple_xml_node_dump ( Eina_Simple_XML_Node *  node,
const char *  indent 
)

Converts the node tree under the given element to a XML string.

Since :
2.3
Parameters:
[in]nodethe base node to convert.
[in]indentIndentation string, or NULL to disable it.
Returns:
NULL on errors or a newly allocated string on success.
Eina_Simple_XML_Node_Root* eina_simple_xml_node_load ( const char *  buf,
unsigned  buflen,
Eina_Bool  strip 
)

Load a XML node tree based on the given string.

Since :
2.3
Parameters:
[in]bufthe input string. May not contain \0 terminator.
[in]buflenthe input string size.
[in]stripwhenever this parser should strip leading and trailing whitespace.
Returns:
Document root with children tags, or NULL on errors. Document with errors may return partial tree instead of NULL, we'll do our best to avoid returning nothing.
void eina_simple_xml_node_processing_free ( Eina_Simple_XML_Node_Data *  node)

Remove processing from parent and delete it.

Since :
2.3
Parameters:
[in]nodeprocessing to release memory.
Eina_Simple_XML_Node_Processing* eina_simple_xml_node_processing_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  contents,
size_t  length 
)

Create new processing. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the processing will be appended to children list.
[in]contentsString to be used. Must not be NULL.
[in]lengthsize in bytes of contents.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_processing_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
void eina_simple_xml_node_root_free ( Eina_Simple_XML_Node_Root *  root)

Free node tree build with eina_simple_xml_node_load()

Since :
2.3
Parameters:
[in]rootmemory returned by eina_simple_xml_node_load()
void eina_simple_xml_node_tag_free ( Eina_Simple_XML_Node_Tag *  tag)

Remove tag from parent and delete it.

Since :
2.3
Parameters:
tagto release memory.
Eina_Simple_XML_Node_Tag* eina_simple_xml_node_tag_new ( Eina_Simple_XML_Node_Tag *  parent,
const char *  name 
)

Create new tag. If parent is provided, it is automatically appended.

Since :
2.3
Parameters:
[in]parentif provided, will be set in the resulting structure as well as the tag will be appended to children list.
[in]nameNull-terminated string. Must not be NULL.
Returns:
Newly allocated memory or NULL on error. This memory should be released with eina_simple_xml_node_tag_free() or indirectly with eina_simple_xml_node_tag_free() of the parent.
Eina_Bool eina_simple_xml_parse ( const char *  buf,
unsigned  buflen,
Eina_Bool  strip,
Eina_Simple_XML_Cb  func,
const void *  data 
)

Parse a section of XML string text.

Since :
2.3
Parameters:
[in]bufthe input string. May not contain \0 terminator.
[in]buflenthe input string size.
[in]stripwhenever this parser should strip leading and trailing whitespace. These whitespace will still be issued, but as type EINA_SIMPLE_XML_IGNORED.
[in]funcwhat to call back while parse to do some action. The first parameter is the given user data, the second is the token type, the third is the pointer to content start (it's not a NULL terminated string!), the forth is where this content is located inside buf (does not include tag start, for instance "<!DOCTYPE value>" the offset points at "value"), the fifth is the size of the content. Whenever this function return EINA_FALSE the parser will abort.
[in]datawhat to give as context to func.
Returns:
EINA_TRUE on success or EINA_FALSE if it was aborted by user or parsing error.
const char* eina_simple_xml_tag_attributes_find ( const char *  buf,
unsigned  buflen 
)

Given the contents of a tag, find where the attributes start.

Since :
2.3
Parameters:
[in]bufthe input string. May not contain \0 terminator.
[in]buflenthe input string size.
Returns:
pointer to the start of attributes, it can be used to feed eina_simple_xml_attributes_parse(). NULL is returned if no attributes were found.
Remarks:
The tag contents is returned by eina_simple_xml_parse() when type is EINA_SIMPLE_XML_OPEN or EINA_SIMPLE_XML_OPEN_EMPTY.