Tizen Native API
|
This is a simplistic relaxed SAX-like XML parser.
This parser is far from being compliant with XML standards, but works for most XMLs out there. If you know that your format is simple and won't vary in the future with strange corner cases, then you can use it safely.
The parser is SAX like, that is, it tokenizes content and calls you back so that you can take some action. No content is allocated during this parser work and it's not recursive, so you can use it with a very large document without any issues.
It does not validate the document anyhow, neither does it create a tree hierarchy. That's up to you.
Accordingly to XML, open tags may contain attributes. This parser does not tokenize this. If you want you can use eina_simple_xml_tag_attributes_find() and then eina_simple_xml_attributes_parse().
Functions | |
Eina_Bool | eina_simple_xml_parse (const char *buf, unsigned buflen, Eina_Bool strip, Eina_Simple_XML_Cb func, const void *data) |
Parses a section of the XML string text. | |
const char * | eina_simple_xml_tag_attributes_find (const char *buf, unsigned buflen) |
Finds where the attributes start from given the contents of a tag are provided. | |
Eina_Bool | eina_simple_xml_attributes_parse (const char *buf, unsigned buflen, Eina_Simple_XML_Attribute_Cb func, const void *data) |
Parses a buffer with XML attributes 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) |
Creates (and appends) a new attribute to the tag. | |
void | eina_simple_xml_attribute_free (Eina_Simple_XML_Attribute *attr) |
Removes an attribute from the parent and deletes it. | |
Eina_Simple_XML_Node_Tag * | eina_simple_xml_node_tag_new (Eina_Simple_XML_Node_Tag *parent, const char *name) |
Creates a new tag. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_tag_free (Eina_Simple_XML_Node_Tag *tag) |
Removes a tag from the parent and deletes it. | |
Eina_Simple_XML_Node_Data * | eina_simple_xml_node_data_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length) |
Creates new data. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_data_free (Eina_Simple_XML_Node_Data *node) |
Removes data from the parent and deletes it. | |
Eina_Simple_XML_Node_CData * | eina_simple_xml_node_cdata_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length) |
Creates new cdata. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_cdata_free (Eina_Simple_XML_Node_Data *node) |
Removes cdata from the parent and deletes it. | |
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) |
Creates a 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) |
Removes the doctype child from the parent and deletes it. | |
Eina_Simple_XML_Node_Processing * | eina_simple_xml_node_processing_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length) |
Creates new processing. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_processing_free (Eina_Simple_XML_Node_Data *node) |
Removes processing from the parent and deletes it. | |
Eina_Simple_XML_Node_Doctype * | eina_simple_xml_node_doctype_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length) |
Creates a new doctype. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_doctype_free (Eina_Simple_XML_Node_Data *node) |
Removes the doctype from the parent and deletes it. | |
Eina_Simple_XML_Node_Comment * | eina_simple_xml_node_comment_new (Eina_Simple_XML_Node_Tag *parent, const char *contents, size_t length) |
Creates a new comment. If parent is provided, it is automatically appended. | |
void | eina_simple_xml_node_comment_free (Eina_Simple_XML_Node_Data *node) |
Removes a comment from the parent and deletes it. | |
Eina_Simple_XML_Node_Root * | eina_simple_xml_node_load (const char *buf, unsigned buflen, Eina_Bool strip) |
Loads an XML node tree based on the given string. | |
void | eina_simple_xml_node_root_free (Eina_Simple_XML_Node_Root *root) |
Frees the node tree built 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 an XML string. | |
Typedefs | |
typedef struct _Eina_Simple_XML_Node_Data | Eina_Simple_XML_Node_Doctype_Child |
Typedef Documentation
typedef struct _Eina_Simple_XML_Node_Data Eina_Simple_XML_Node_Doctype_Child |
- Since (EFL) :
- 1.8
Enumeration Type Documentation
Enumeration for a simple XML type.
- Enumerator:
Function Documentation
void eina_simple_xml_attribute_free | ( | Eina_Simple_XML_Attribute * | attr | ) |
Removes an attribute from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] attr The attribute to release memory of
Eina_Simple_XML_Attribute* eina_simple_xml_attribute_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | key, | ||
const char * | value | ||
) |
Creates (and appends) a new attribute to the tag.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the attribute is appended to the attributes list [in] key The null-terminated string
Must not beNULL
.[in] value The null-terminated string
IfNULL
, the empty string is used.
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory should be released directly 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 | ||
) |
Parses a buffer with XML attributes to key=value pairs.
- Since :
- 2.3.1
- Parameters:
-
[in] buf The input string
May not contain \0 terminator.[in] buflen The input string size [in] func The function to call back while parse does 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 the reference is just valid till the function returns[in] data The data to pass to the callback function
- Returns:
EINA_TRUE
on success, otherwiseEINA_FALSE
if it is aborted by the user or a parsing error occurs
void eina_simple_xml_node_cdata_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes cdata from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] node The cdata to release memory of
Eina_Simple_XML_Node_CData* eina_simple_xml_node_cdata_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | contents, | ||
size_t | length | ||
) |
Creates new cdata. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the cdata is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_cdata_free() or indirectly with eina_simple_xml_node_tag_free().
void eina_simple_xml_node_comment_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes a comment from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] node The comment to release memory of
Eina_Simple_XML_Node_Comment* eina_simple_xml_node_comment_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | contents, | ||
size_t | length | ||
) |
Creates a new comment. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the comment is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_comment_free() or indirectly with eina_simple_xml_node_tag_free().
void eina_simple_xml_node_data_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes data from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] node The data to release memory of
Eina_Simple_XML_Node_Data* eina_simple_xml_node_data_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | contents, | ||
size_t | length | ||
) |
Creates new data. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the data is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_data_free() or indirectly with eina_simple_xml_node_tag_free().
void eina_simple_xml_node_doctype_child_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes the doctype child from the parent and deletes it.
- Since (EFL) :
- 1.8
- Since :
- 2.3.1
- Parameters:
-
[in] node The doctype child to release memory of
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 | ||
) |
Creates a new doctype child. If parent is provided, it is automatically appended.
- Since (EFL) :
- 1.8
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the doctype child is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_doctype_child_free() or indirectly with eina_simple_xml_node_tag_free().
void eina_simple_xml_node_doctype_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes the doctype from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] node The doctype to release memory of
Eina_Simple_XML_Node_Doctype* eina_simple_xml_node_doctype_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | contents, | ||
size_t | length | ||
) |
Creates a new doctype. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the doctype is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_doctype_free() or indirectly with eina_simple_xml_node_tag_free().
char* eina_simple_xml_node_dump | ( | Eina_Simple_XML_Node * | node, |
const char * | indent | ||
) |
Converts the node tree under the given element to an XML string.
- Since :
- 2.3.1
- Parameters:
-
[in] node The base node to convert [in] indent The indentation string, otherwise NULL
to disable it
- Returns:
NULL
on errors, otherwise a newly allocated string on success
Eina_Simple_XML_Node_Root* eina_simple_xml_node_load | ( | const char * | buf, |
unsigned | buflen, | ||
Eina_Bool | strip | ||
) |
Loads an XML node tree based on the given string.
- Since :
- 2.3.1
- Parameters:
-
[in] buf The input string
May not contain \0 terminator.[in] buflen The input string size [in] strip The boolean value that indicates when this parser should do strip leading and whitespace trailing
- Returns:
- The document root with children tags, otherwise
NULL
on errors
The document with errors may return a partial tree instead ofNULL
, we are going to do our best to avoid returning nothing.
void eina_simple_xml_node_processing_free | ( | Eina_Simple_XML_Node_Data * | node | ) |
Removes processing from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] node The processing to release memory of
Eina_Simple_XML_Node_Processing* eina_simple_xml_node_processing_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | contents, | ||
size_t | length | ||
) |
Creates new processing. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the processing is appended to the children list [in] contents The string to be used
Must not beNULL
.[in] length size in bytes of contents
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_processing_free() or indirectly with eina_simple_xml_node_tag_free().
void eina_simple_xml_node_root_free | ( | Eina_Simple_XML_Node_Root * | root | ) |
Frees the node tree built with eina_simple_xml_node_load().
- Since :
- 2.3.1
- Parameters:
-
[in] root The memory returned by eina_simple_xml_node_load()
void eina_simple_xml_node_tag_free | ( | Eina_Simple_XML_Node_Tag * | tag | ) |
Removes a tag from the parent and deletes it.
- Since :
- 2.3.1
- Parameters:
-
[in] tag The tag to release memory of
Eina_Simple_XML_Node_Tag* eina_simple_xml_node_tag_new | ( | Eina_Simple_XML_Node_Tag * | parent, |
const char * | name | ||
) |
Creates a new tag. If parent is provided, it is automatically appended.
- Since :
- 2.3.1
- Parameters:
-
[in] parent If provided, this is set in the resulting structure and the tag is appended to the children list [in] name The null-terminated string
Must not beNULL
.
- Returns:
- The newly allocated memory, otherwise
NULL
on error
This memory of the parent should be released directly with eina_simple_xml_node_tag_free() or indirectly with eina_simple_xml_node_tag_free().
Eina_Bool eina_simple_xml_parse | ( | const char * | buf, |
unsigned | buflen, | ||
Eina_Bool | strip, | ||
Eina_Simple_XML_Cb | func, | ||
const void * | data | ||
) |
Parses a section of the XML string text.
- Since :
- 2.3.1
- Parameters:
-
[in] buf The input string
May not contain the \0 terminator.[in] buflen The input string size [in] strip The boolean value that indicates when this parser should do strip leading and whitespace trailing
This whitespace is still issued, but as type EINA_SIMPLE_XML_IGNORED.[in] func The function to call back while parse does some action
The first parameter is the given user data, the second is the token type, the third is the pointer to the content's start (it's not a NULL terminated string), the fourth is where this content is located, that is 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 returnsEINA_FALSE
the parser aborts.[in] data The data to give as context to func
- Returns:
EINA_TRUE
on success, otherwiseEINA_FALSE
if it is aborted by the user or a parsing error occurs
const char* eina_simple_xml_tag_attributes_find | ( | const char * | buf, |
unsigned | buflen | ||
) |
Finds where the attributes start from given the contents of a tag are provided.
- Since :
- 2.3.1
- Remarks:
- The tag contents are returned by eina_simple_xml_parse() when type is EINA_SIMPLE_XML_OPEN or EINA_SIMPLE_XML_OPEN_EMPTY.
- Parameters:
-
[in] buf The input string
May not contain \0 terminator.[in] buflen The input string size
- Returns:
- A pointer to the start of the attributes, it can be used to feed eina_simple_xml_attributes_parse()
NULL
is returned if no attributes are found.