Commit c67d9de5 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Feature: Added functions to get a node from report XML by it's type

parent 2a370ccc
......@@ -286,6 +286,14 @@ reportxml_node_t * reportxml_get_node_by_attribute(reportxml_t *report, con
return reportxml_node_get_child_by_attribute(report->root, key, value, include_definitions);
}
reportxml_node_t * reportxml_get_node_by_type(reportxml_t *report, reportxml_node_type_t type, int include_definitions)
{
if (!report)
return NULL;
return reportxml_node_get_child_by_type(report->root, type, include_definitions);
}
reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc)
{
reportxml_node_t *root;
......@@ -822,6 +830,33 @@ reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *
return NULL;
}
reportxml_node_t * reportxml_node_get_child_by_type(reportxml_node_t *node, reportxml_node_type_t type, int include_definitions)
{
size_t i;
if (!node)
return NULL;
if (node->type == type) {
if (refobject_ref(node) != 0)
return NULL;
return node;
}
if (node->type == REPORTXML_NODE_TYPE_DEFINITION && !include_definitions)
return NULL;
for (i = 0; i < node->childs_len; i++) {
reportxml_node_t *ret;
ret = reportxml_node_get_child_by_type(node->childs[i], type, include_definitions);
if (ret != NULL)
return ret;
}
return NULL;
}
int reportxml_node_set_content(reportxml_node_t *node, const char *value)
{
const struct nodedef *nodedef;
......
......@@ -77,6 +77,8 @@ reportxml_node_t * reportxml_get_root_node(reportxml_t *report);
* <definition>s are skipped.
*/
reportxml_node_t * reportxml_get_node_by_attribute(reportxml_t *report, const char *key, const char *value, int include_definitions);
/* This gets a node by it's type. Otherwise identical to reportxml_get_node_by_attribute() */
reportxml_node_t * reportxml_get_node_by_type(reportxml_t *report, reportxml_node_type_t type, int include_definitions);
/* This function parses an XML document and returns the parst report XML document */
reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc);
/* This function renders an report XML document as XML structure */
......@@ -108,6 +110,8 @@ ssize_t reportxml_node_count_child(reportxml_node_t *node);
reportxml_node_t * reportxml_node_get_child(reportxml_node_t *node, size_t idx);
/* This gets an child by it's value of the given attribute. See reportxml_get_node_by_attribute() for more details. */
reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *node, const char *key, const char *value, int include_definitions);
/* This gets a child by it's type. Otherwise identical to reportxml_node_get_child_by_attribute() */
reportxml_node_t * reportxml_node_get_child_by_type(reportxml_node_t *node, reportxml_node_type_t type, int include_definitions);
/* This gets and sets the text content of an node (used for <text>) */
int reportxml_node_set_content(reportxml_node_t *node, const char *value);
char * reportxml_node_get_content(reportxml_node_t *node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment