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



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

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
subtree. 

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.

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]