diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dmixml.c | 35 | ||||
-rw-r--r-- | src/dmixml.h | 2 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/dmixml.c b/src/dmixml.c index a9ecd67..f8a6219 100644 --- a/src/dmixml.c +++ b/src/dmixml.c @@ -28,6 +28,7 @@ #include <assert.h> #include <libxml/tree.h> +#include <libxml/xpath.h> #include <libxml/xmlstring.h> // Internal function for dmixml_* functions ... builds up a variable xmlChar* string @@ -202,10 +203,42 @@ xmlNode *dmixml_FindNode(xmlNode *node, const char *key) { inline char *dmixml_GetContent(xmlNode *node) { // FIXME: Should find better way how to return UTF-8 data - return (((node != NULL) && (node->children != NULL)) ? (char *) node->children->content : "(not set)"); + return (((node != NULL) && (node->children != NULL)) ? (char *) node->children->content : NULL); } inline char *dmixml_GetNodeContent(xmlNode *node, const char *key) { return dmixml_GetContent(dmixml_FindNode(node, key)); } +char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx) { + char *ret = NULL; + + if( xpo == NULL ) { + return NULL; + } + + switch( xpo->type ) { + case XPATH_STRING: + ret = (char *)xpo->stringval; + break; + + case XPATH_NUMBER: + ret = (char *) malloc(34); + memset(ret, 0, 34); + snprintf(ret, 32, "%f", xpo->floatval); + break; + + case XPATH_NODESET: + ret = ( (xpo->nodesetval->nodeNr >= (idx+1)) + ? dmixml_GetContent(xpo->nodesetval->nodeTab[idx]) + : NULL); + break; + + default: + fprintf(stderr, "dmixml_GetXPathContent(...):: " + "Do not know how to handle XPath type %i\n", + xpo->type); + } + return ret; +} + diff --git a/src/dmixml.h b/src/dmixml.h index 4683bc9..7176483 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -28,6 +28,7 @@ #include <stdarg.h> #include <libxml/tree.h> +#include <libxml/xpath.h> xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); @@ -37,5 +38,6 @@ char *dmixml_GetAttrValue(xmlNode *node, const char *key); xmlNode *dmixml_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); +char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx); #endif |