[Fwd: Re: [xml] XPath relative search?]




Oops. I accidentally sent this offlist only. Here is the forward of
it.
        Apologies,
        B
--
-------------------------------------------------------------------
Dr Balint Joo                         Post Doctoral Research Fellow
School of Physics
University of Edinburgh
Mayfield Road, Edinburgh EH9 3JZ
Scotland UK
Tel: 0131 650 6469 (from UK) +44-131-650-6469 (from outwith UK)
Fax: 0131 650 5902 (from UK) +44-131-650-5902 (from outwith UK)
email: bj ph ed ac uk           bj phys columbia edu
WWW  : http://www.ph.ed.ac.uk/~bj
-------------------------------------------------------------------
--- Begin Message ---


How, then, does one do a relative XPath search?  I'm mystified.
Any help is appreciated.


I erm just do it by setting the context node pointer in the
xpath_context.

Consider the following code. First do an absolute search
to xpath held in xpath_string. Then do a relative search...

 xpath_context = xmlXPathNewContext(doc);

 query_result = xmlXPathEval((const xmlChar *)xpath_string,
                                  xpath_context);


 /* Checks to see we have a result */
 if( query_result == NULL ) {
        BARF("Null XPath Query Result");
 }

 if( query_result->nodesetval == NULL ) {
        BARF("Null node set in query result");
}

 if( query_result->nodesetval->nodeNr != 1 ) {
        BARF("Query didnt select unique node");
}

/* Now reset the context */
xpath_context->node = query_result->nodesetval->nodeTab[0];

/* Now do relative search */
xmlXPathFreeObject(query_result);

/* Once again apologies for not handling xmlChar* correctly */

query_result = xmlXPathEval((const xmlChar *)"//text",
                            xpath_context);

/* More stuff goes here */



All the best,
        Balint


--
-------------------------------------------------------------------
Dr Balint Joo                         Post Doctoral Research Fellow
School of Physics
University of Edinburgh
Mayfield Road, Edinburgh EH9 3JZ
Scotland UK
Tel: 0131 650 6469 (from UK) +44-131-650-6469 (from outwith UK)
Fax: 0131 650 5902 (from UK) +44-131-650-5902 (from outwith UK)
email: bj ph ed ac uk           bj phys columbia edu
WWW  : http://www.ph.ed.ac.uk/~bj
-------------------------------------------------------------------


--- End Message ---


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