diff options
| -rw-r--r-- | xml-parser.c | 41 | ||||
| -rw-r--r-- | xml-parser.h | 4 |
2 files changed, 33 insertions, 12 deletions
diff --git a/xml-parser.c b/xml-parser.c index 88373dd..444ea58 100644 --- a/xml-parser.c +++ b/xml-parser.c @@ -81,14 +81,17 @@ xml_parser_close (TXMLFile *file) /* - * xml_file_get_node_value: retrieve value from XPath node + * xml_file_get_node_value: retrieve string value from XPath node + * - multiple matched nodes will be concatenated into one string + * - otherwise please use [0], [1] etc. quantificators */ char * xml_file_get_node_value (TXMLFile *file, const char *x_path) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; - char *val; + char *val, *valx; + int i; if ((! file) || (! x_path)) return NULL; @@ -102,15 +105,31 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) val = NULL; if ((xpathObj->nodesetval) && (xpathObj->nodesetval->nodeNr > 0)) { - cur = xpathObj->nodesetval->nodeTab[0]; - - #ifdef __DEBUG_ALL__ - printf("Result (%d nodes):\n", xpathObj->nodesetval->nodeNr); - printf(" XPATH matched: element node \"%s\", value = '%s'\n", cur->name, cur->content); - #endif - - if (cur->content) - val = strdup ((char *) cur->content); + #ifdef __DEBUG_ALL__ + printf("Result (%d nodes):\n", xpathObj->nodesetval->nodeNr); + #endif + + for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) + { + cur = xpathObj->nodesetval->nodeTab[i]; + #ifdef __DEBUG_ALL__ + printf(" XPATH matched: element node \"%s[%d]\", value = '%s'\n", cur->name, i, cur->content); + #endif + + if (cur->content) + { + if (val == NULL) + { + val = g_strdup ((char *) cur->content); + } + else + { + valx = g_strconcat (val, (char *) cur->content, NULL); + g_free (val); + val = valx; + } + } + } } xmlXPathFreeObject (xpathObj); diff --git a/xml-parser.h b/xml-parser.h index 53d7b5a..e130e5b 100644 --- a/xml-parser.h +++ b/xml-parser.h @@ -39,7 +39,9 @@ TXMLFile * xml_parser_load (const char *filename); void xml_parser_close (TXMLFile *file); /* - * xml_file_get_node_value: retrieve value from XPath node + * xml_file_get_node_value: retrieve string value from XPath node + * - multiple matched nodes will be concatenated into one string + * - otherwise please use [0], [1] etc. quantificators */ char * xml_file_get_node_value (TXMLFile *file, const char *x_path); |
