diff options
Diffstat (limited to 'xml-parser.c')
| -rw-r--r-- | xml-parser.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/xml-parser.c b/xml-parser.c index 2b3005a..eb6c86f 100644 --- a/xml-parser.c +++ b/xml-parser.c @@ -79,6 +79,37 @@ xml_parser_close (TXMLFile *file) } } +/* + * xml_file_get_node_name: retrieve name of the XPath node + */ +char * +xml_file_get_node_name (TXMLFile *file, const char *x_path) +{ + xmlXPathObjectPtr xpathObj; + xmlNodePtr cur; + char *attrv; + + if ((! file) || (! x_path)) + return NULL; + + /* Evaluate xpath expression */ + xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); + if (xpathObj == NULL) { + fprintf (stderr, "Error: unable to evaluate xpath expression \"%s\"\n", x_path); + return NULL; + } + + attrv = NULL; + if ((xpathObj->nodesetval) && (xpathObj->nodesetval->nodeNr > 0)) { + cur = xpathObj->nodesetval->nodeTab[0]; + if (cur->name) + attrv = strdup ((const char *) cur->name); + } + + xmlXPathFreeObject (xpathObj); + return attrv; +} + /* * xml_file_get_node_value: retrieve string value from XPath node |
