Re: [xml] XPath doing a search on a subtree

On Mon, Oct 02, 2006 at 06:14:43PM -0700, Andric, Milan wrote:

I have a xmlNodePtr pointing to a particular node in a DOM tree.  
I'd like to execute XPath relative search on subtree from that node down
(i.e. on the subtree for which this node is the top node). In particular
I'd like to find all recurerrences of a particular node within this

So far I've tried code below, but it does a search for entire DOM, not
just a relative subtree (i.e. from a particular node down):

I would appreciate your help in what might be causing this to execute
for every node in DOM, instead just for subtree as pointed by current
(referent) node. 
      context = xmlXPathNewContext(xmlNode->doc);
      if (context == NULL) {
              printf("Error in xmlXPathNewContext\n");
              return NULL;

      context->node = xmlNode ; 

  that should work. Make sure you use the .// construct and not the // one !
I.e. check the semantic of your XPath query.


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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