summaryrefslogtreecommitdiffstats
path: root/src/dmixml.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-04-29 18:29:50 +0200
committerDavid Sommerseth <davids@redhat.com>2009-04-29 18:29:50 +0200
commitd64ab66e4fbf8d6dfceed628aef21f01063c3d66 (patch)
tree1011afe6d3346508617694db7862adb9e8ae9243 /src/dmixml.c
parenta3047723df9b66b6a56bcc72a469a129bbaf4d54 (diff)
downloadpython-dmidecode-d64ab66e4fbf8d6dfceed628aef21f01063c3d66.tar.gz
python-dmidecode-d64ab66e4fbf8d6dfceed628aef21f01063c3d66.tar.xz
python-dmidecode-d64ab66e4fbf8d6dfceed628aef21f01063c3d66.zip
Added function for retrieving values from XPath objects
Reverted commit 75aaf67d43cf4a28fe8d3e07111dab75a0c4396d in addition
Diffstat (limited to 'src/dmixml.c')
-rw-r--r--src/dmixml.c35
1 files changed, 34 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;
+}
+