Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - libxml: persistence of xmlXPathObject.nodeset->nodeTab elements

 
Thread Tools Search this Thread
Old 07-13-2006, 06:03 PM   #1
Default libxml: persistence of xmlXPathObject.nodeset->nodeTab elements


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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump