diff options
author | David Sommerseth <davids@redhat.com> | 2009-04-09 15:13:23 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-04-29 11:22:11 +0200 |
commit | 46988f9abcec9eb072be5f5d52fc594de89478e8 (patch) | |
tree | 239800724c90846c07dc1922c5577f5bc8bdeb6e | |
parent | 8b2fe610dc309579f07787696f0814c359aa4de1 (diff) | |
download | python-dmidecode-46988f9abcec9eb072be5f5d52fc594de89478e8.tar.gz python-dmidecode-46988f9abcec9eb072be5f5d52fc594de89478e8.tar.xz python-dmidecode-46988f9abcec9eb072be5f5d52fc594de89478e8.zip |
Added more XML functions
-rw-r--r-- | src/dmixml.c | 53 | ||||
-rw-r--r-- | src/dmixml.h | 5 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/dmixml.c b/src/dmixml.c index 8be62ff..0feb90c 100644 --- a/src/dmixml.c +++ b/src/dmixml.c @@ -141,3 +141,56 @@ xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...) return res; } + +char *dmixml_GetAttrValue(xmlNode *node, const char *key) { + xmlAttr *aptr = NULL; + xmlChar *key_s = NULL; + + if( node == NULL ) { + return NULL; + } + + key_s = xmlCharStrdup(key); + assert( key_s != NULL ); + + for( aptr = node->properties; aptr != NULL; aptr = aptr->next ) { + if( xmlStrcmp(aptr->name, key_s) == 0 ) { + free(key_s); key_s = NULL; + // FIXME: Should find better way how to return UTF-8 data + return (char *)(aptr->children != NULL ? aptr->children->content : NULL); + } + } + free(key_s); key_s = NULL; + return NULL; +} + +xmlNode *dmixml_FindNode(xmlNode *node, const char *key) { + xmlNode *ptr_n = NULL; + xmlChar *key_s = NULL; + + if( node->children == NULL ) { + return NULL; + } + + key_s = xmlCharStrdup(key); + assert( key_s != NULL ); + + for( ptr_n = node->children; ptr_n != NULL; ptr_n = ptr_n->next ) { + if( xmlStrcmp(ptr_n->name, key_s) == 0 ) { + free(key_s); key_s = NULL; + return ptr_n; + } + } + free(key_s); key_s = NULL; + return NULL; +} + +inline char *dmixml_GetContent(xmlNode *node) { + // FIXME: Should find better way how to return UTF-8 data + return (char *) (((node != NULL) && (node->children != NULL)) ? node->children->content : NULL); +} + +inline char *dmixml_GetNodeContent(xmlNode *node, const char *key) { + return dmixml_GetContent(dmixml_FindNode(node, key)); +} + diff --git a/src/dmixml.h b/src/dmixml.h index e3b99a9..4683bc9 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -33,4 +33,9 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...); +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); + #endif |