![]() |
|
|
|||||||
![]() |
XML - libxml: persistence of xmlXPathObject.nodeset->nodeTab elements |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi all
I want to use an xpath query to get a set of xmlNodePtr , but I don't want to keep the xmlXPathObject around. See the function below. I want to: * make xpath query and get an xmlXPathObjectPtr back * get a pointer (np) to the XPathObjectPtr->nodesetval->nodeTab[0] * free XPathObjectPtr * return the pointer np ... but I'm not sure if np is still valid after deleting the XPathObjectPtr Can someone help me puzzle it out? xmlNodePtr get_first_result_from_xpath(xmlDocPtr doc, xmlChar *xpath) { xmlXPathContextPtr context; xmlXPathObjectPtr result; xmlNodePtr np; context = xmlXPathNewContext(doc); if (context == NULL) { return NULL; } result = xmlXPathEvalExpression(xpath, context); xmlXPathFreeContext(context); if (result == NULL) { return NULL; } if(xmlXPathNodeSetIsEmpty(result->nodesetval)){ xmlXPathFreeObject(result); return NULL; } nodeset = result->nodesetval; if (nodeset->nodeNr) { np = nodeset->nodeTab[0]; xmlXPathFreeObject(result); // // QUESTION: is np still valid after I delete "result"? // return np; } return NULL; } H-P Hoi-Polloi |
|
|