diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dmixml.c | 16 | ||||
-rw-r--r-- | src/dmixml.h | 35 | ||||
-rw-r--r-- | src/xmlpythonizer.c | 2 |
3 files changed, 46 insertions, 7 deletions
diff --git a/src/dmixml.c b/src/dmixml.c index 1092872..5d9f1a1 100644 --- a/src/dmixml.c +++ b/src/dmixml.c @@ -213,20 +213,24 @@ char *dmixml_GetAttrValue(xmlNode *node, const char *key) { } /** - * Retrieve a pointer to an XML node based on tag name and a specified attribute value. To get - * a hit, tag name and the attribute must be found and the value of the attribute must match as well. - * The function will traverse all children nodes of the given input node, but it will not go deeper. + * Internal function - Retrieve a pointer to an XML node based on tag name and a specified attribute + * value. To get a hit, tag name and the attribute must be found and the value of the attribute must + * match as well. The function will traverse all children nodes of the given input node, but it will + * not go deeper. * @author David Sommerseth <davids@redhat.com> * @author Nima Talebi <nima@autonomy.net.au> * @param xmlNode* Pointer to the XML node of where to start searching * @param const char* Tag name the function will search for * @param const char* Attribute to check for in the tag * @param const char* Value of the attribute which must match to have a hit + * @param int Be case sensitive or not. 1 == case sensitive, 0 == case insensitive * @return xmlNode* Pointer to the found XML node, NULL if no tag was found. */ -xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *attrkey, const char *val) { +xmlNode *__dmixml_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *attrkey, + const char *val, int casesens) { xmlNode *ptr_n = NULL; xmlChar *tag_s = NULL; + int (*compare_func) (const char *, const char *); assert( node != NULL ); if( node->children == NULL ) { @@ -236,12 +240,14 @@ xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *at tag_s = xmlCharStrdup(tagkey); assert( tag_s != NULL ); + compare_func = (casesens == 1 ? strcmp : strcasecmp); + foreach_xmlnode(node->children, ptr_n) { // To return the correct node, we need to check node type, // tag name and the attribute value of the given attribute. if( (ptr_n->type == XML_ELEMENT_NODE) && (xmlStrcmp(ptr_n->name, tag_s) == 0) - && (strcmp(dmixml_GetAttrValue(ptr_n, attrkey), val) == 0 ) ) { + && (compare_func(dmixml_GetAttrValue(ptr_n, attrkey), val) == 0 ) ) { goto exit; } } diff --git a/src/dmixml.h b/src/dmixml.h index c78d8b0..3dc32e5 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -37,7 +37,40 @@ 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_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *attrkey, const char *val); + +xmlNode *__dmixml_FindNodeByAttr(xmlNode *, const char *, const char *, const char *, int); + +/** + * Retrieve a pointer to an XML node based on tag name and a specified attribute value. To get + * a hit, tag name and the attribute must be found and the value of the attribute must match as well. + * The function will traverse all children nodes of the given input node, but it will not go deeper. + * Matching is case sensitive. + * @author David Sommerseth <davids@redhat.com> + * @author Nima Talebi <nima@autonomy.net.au> + * @param xmlNode* Pointer to the XML node of where to start searching + * @param const char* Tag name the function will search for + * @param const char* Attribute to check for in the tag + * @param const char* Value of the attribute which must match to have a hit + * @return xmlNode* Pointer to the found XML node, NULL if no tag was found. + */ +#define dmixml_FindNodeByAttr(n, t, a, v) __dmixml_FindNodeByAttr(n, t, a, v, 1) + +/** + * Retrieve a pointer to an XML node based on tag name and a specified attribute value. To get + * a hit, tag name and the attribute must be found and the value of the attribute must match as well. + * The function will traverse all children nodes of the given input node, but it will not go deeper. + * Matching is case INsensitive. + * @author David Sommerseth <davids@redhat.com> + * @author Nima Talebi <nima@autonomy.net.au> + * @param xmlNode* Pointer to the XML node of where to start searching + * @param const char* Tag name the function will search for + * @param const char* Attribute to check for in the tag + * @param const char* Value of the attribute which must match to have a hit + * @return xmlNode* Pointer to the found XML node, NULL if no tag was found. + */ +#define dmixml_FindNodeByAttr_NoCase(n, t, a, v) __dmixml_FindNodeByAttr(n, t, a, v, 0) + + xmlNode *dmixml_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); diff --git a/src/xmlpythonizer.c b/src/xmlpythonizer.c index a9282e2..47590dd 100644 --- a/src/xmlpythonizer.c +++ b/src/xmlpythonizer.c @@ -458,7 +458,7 @@ ptzMAP *_dmimap_parse_mapping_node_typeid(xmlNode *mapnode, const char *typeid) assert( mapnode != NULL); // Find the <TypeMap> tag with our type ID - node = dmixml_FindNodeByAttr(mapnode, "TypeMap", "id", typeid); + node = dmixml_FindNodeByAttr_NoCase(mapnode, "TypeMap", "id", typeid); if( node == NULL ) { // No exception handling possible here, as we don't return PyObject fprintf(stderr,"** WARNING: Could not find any XML->Python " |