I use g++ and libxml2
static void print_element_names(xmlNode * a_node,xmlDoc * doc) {
xmlNode *cur_node = NULL;
const char *c= "city";
xmlChar *name;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
std::cout<<convert(cur_node)<<std::endl;
}
if (convert(cur_node)==c){
//work but not equal with city
std::cout<<"Found node"<<std::endl;
}
print_element_names(cur_node->children,doc);
}
}
char * convert(xmlNode * a_node) {
char* a = (char *)a_node->name;
return a;
}
address_book
person
name
address
street
city
state
zip
phone
It not equal with "city" maybe becuase xmlChar and char. How can I compare nodename with char ?
Your convert(cur_node)==c
is comparing pointers instead of comparing string contents, which isn't the way to compare strings in C++.
Try using strncmp to compare the two.