Это результат вызова rest, и мне нужно только выбрать значения нескольких элементов (содержимое).
Кажется, все работает нормально, функция " findNodeName()" находит мой элемент и выбирает его содержимое.
Но я хочу вернуть текущий узел (cur_node) обратно вызывающему объекту для последующей обработки.
Я знаю, что я делаю что-то не так, но не могу понять этого.
Почему xmlNodePtr имеет значение NULL, когда возвращается к вызывающей функции?
Код: Выделить всё
xmlNodePtr findNodeName(xmlNodePtr a_node, char **findIt)
{
xmlNodePtr cur_node = a_node; // a_node is the root node, picked upl earlier.
char *key = *findIt; // Key is what I'm looking for
xmlChar *result = NULL;
xmlNode *tmpNode = NULL;
if (a_node == NULL) {
printf("Empty document\n");
return(NULL);
}
while (cur_node) {
//printf("cur_node->name = %s, type = %d\n", cur_node->name, cur_node->type);
if ((!xmlStrcmp(cur_node->name, (const xmlChar *) key ))) {
printf("Node is: %s\n", cur_node->name); // Work fine
//tmpNode = xmlCopyNode(cur_node, 1); // Test
//printf("tmpNode: %s\n", cur_node->name); // Also works fine
result = xmlNodeGetContent(cur_node->children);
printf("Result: %s, ptr = %p\n", (char*)result, (void*)&result); // No problem here either, got value (which is "true")
if (cur_node != NULL) {
return(cur_node); // It's not NULL here
}
}
cur_node = cur_node->next;
}
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if ((cur_node->type == XML_ELEMENT_NODE)) {
findNodeName(cur_node->children, findIt);
}
}
return (NULL);
}
Calling function
int parseDocument(xmlstring *s)
{
xmlDoc *doc;
xmlChar *key;
xmlNodePtr current;
xmlNodePtr found;
xmlChar *value;
......
......
printf("Where are we: %s\n", current->name);
char *searchNode = "IndividinformationGrunduppgifter"; // The node I'm looking for
while (current != NULL) {
if (current->type == XML_ELEMENT_NODE) {
found = findNodeName(current, &searchNode);
if (found != NULL) {
// **Here is my problem, function findNodeName return's a NULL xmlNodePtr**
// Always NULL here,
key = getSekretessValue(found);
printf("Key: %s\n", key);
} else {
printf("found = NULL\n");
}
current = current->next;
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... t-but-retu