U
Uwe Grawert
I have the following recursive function:
string find_value_by_key (xmlDocPtr doc,
xmlNodePtr root_node,
const string& key)
{
while(root_node != NULL)
{
if(! xmlStrcmp( root_node->name, (xmlChar*)key.c_str() ) ) {
cout << root_node->name << ": " << xmlNodeListGetString(doc,
root_node->xmlChildrenNode, 1);
return string((char*) xmlNodeListGetString(doc,
root_node->xmlChildrenNode, 1));
}
if(root_node->children)
find_value_by_key(doc, root_node->children, key);
root_node = root_node->next;
}
return string("Nothing!");
}
I can find the element and it prints the value. but the return is
always "Nothing!".
i think i make a classical mistake, but have no idea why the function does
not return the value of the element???
string find_value_by_key (xmlDocPtr doc,
xmlNodePtr root_node,
const string& key)
{
while(root_node != NULL)
{
if(! xmlStrcmp( root_node->name, (xmlChar*)key.c_str() ) ) {
cout << root_node->name << ": " << xmlNodeListGetString(doc,
root_node->xmlChildrenNode, 1);
return string((char*) xmlNodeListGetString(doc,
root_node->xmlChildrenNode, 1));
}
if(root_node->children)
find_value_by_key(doc, root_node->children, key);
root_node = root_node->next;
}
return string("Nothing!");
}
I can find the element and it prints the value. but the return is
always "Nothing!".
i think i make a classical mistake, but have no idea why the function does
not return the value of the element???