diff --git a/src/reportxml.c b/src/reportxml.c index cfc21a1f..b6ea1c7e 100644 --- a/src/reportxml.c +++ b/src/reportxml.c @@ -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; diff --git a/src/reportxml.h b/src/reportxml.h index 2be09dc8..68d4b3d8 100644 --- a/src/reportxml.h +++ b/src/reportxml.h @@ -77,6 +77,8 @@ reportxml_node_t * reportxml_get_root_node(reportxml_t *report); * 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 ) */ int reportxml_node_set_content(reportxml_node_t *node, const char *value); char * reportxml_node_get_content(reportxml_node_t *node);