SYNOPSISxmlNode xmlTreeXPathSetContext(xmlXPath xpath, xmlNode node)
Parameters:
xpath - the xmlXPath to set a context fornode - the new starting context for xpath
Returns:
DESCRIPTIONxmlTreeXPathSetContext() lets you set a starting context for
the xpath. This lets you perform relative XPath queries, starting from that
node, instead of the document root.
Absolute queries (that start with /) are not affected by the context.
The context is the xmlDoc by default, and can be reset by passing the
xmlDoc to xmlTreeXPathSetContext.
EXAMPLE<capture>
<?xml version="1.0"?>
<results>
<result>
<data type="name">Result 1</data>
<data type="location">http://www.example.com/one</data>
</result>
<result>
<data type="name">Result 2</data>
<data type="location">http://www.example.com/two</data>
</result>
</results>
</capture><$xml = $ret>
<$doc = (xmlTreeNewDocFromString($xml, 'XML_PARSE_NOBLANKS'))>
<$root = (xmlTreeGetRootElement($doc))>
<$firstResult = (xmlTreeGetFirstChild($root))>
<$xpath = (xmlTreeNewXPath($doc))>
<$ret = (xmlTreeXPathSetContext($xpath, $firstResult))>
<capture>data[@type='name']</capture>
<$nodes = (xmlTreeXPathExecute($xpath, $ret))>
<loop $nodes>
<$ret = (xmlTreeGetContent($nodes))>
<fmt "Matched %s\n" $ret>
</loop>
SEE ALSOxmlTreeNewXPath,
xmlTreeXPathExecute