[xml] Using Xpath from a node



Israel Ganor writes:
Hi,

I've just starting using libxml2.
I wonder if there is a way to the the context of an element using a relative
Xpath expression. E.g., soppose my xmlNodePtr points to the last B element
(see below). Now I want to directly read the text of subelement E, without
looping through all B's subelements. Is this possible? The only way I found
so far is to build the full Xpath of E (from the doc's root) and get it
using the full expression, but this looks like an non-elegant and
inefficient.

        I *think* you can set the "node" element in the
xmlXPathContext object to point to the node you want to start from.
E.g, something like 

    xmlXPathContextPtr xpathCtxt;
    xmlXPathObjectPtr xpathObj;

    xpathCtxt = xmlXPathNewContext(doc_);
    xpathCtxt->node = node_;
    xpathObj = xmlXPathEvalExpression((const xmlChar *) selectstr_, 
                                      xpathCtxt);

    ...

        I may be wrong on this, but it is my current working
assumption :-)

-- 
Raymond Wiker                        Mail:  Raymond Wiker fast no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/




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