Re: [xml] Questions on usage: xmlTextReaderCurrentDoc, XPath and xmlTextReaderRead



On Mon, Dec 24, 2007 at 04:06:27PM -0500, Eric West wrote:
[...]
What was not obvious in the xmlTextReader+XPath example was where
to get a pointer to the current xmlDocPtr without calling
xmlTextReaderCurrentDoc(). I did some further experimenting and
found that one may use the xmlDocPtr from the xmlNodePtr returned
by xmlTextReaderExpand(). For example:

   node = xmlTextReaderExpand( reader);
   pathContext = xmlXPathNewContext( node->doc);
   pathContext->node = node;
   obj = xmlXPathEval( BAD_CAST xmlXPathQuery, pathContext);

With this revision of my code and replacement of xmlFree() with
the appropriate variant (eg xmlXPathFreeObject, xmlXPathFreeContext)
I was able to get valgrind to give my code a clean bill of health.

Question: is the above code sequence valid??? (Just because it works,
is not much of a measure of correctness. :)  )

  As long as your XPath query is relative to the node and uses only
the descendants and ancestors of the node that should be reliable.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]