SYNOPSISxmlNode xmlTreeXPathExecute(xmlXPath xpath, string expression)
Parameters:
xpath - an xmlXPath objectexpression - the XPath expression to execute
Returns:
xmlNode's that match the XPath expression
DESCRIPTIONxmlTreeXPathExecute() executes an XPath expression, returning all
xmlNode's that match the expression. It operates on an xmlXPath
object, which can be obtained from a doc with xmlTreeNewXPath().
If the specified XPath returns a basic data type such as a string
(like name(/*)) or a number (like
string-length(name(/*)), then it will be contained in a single
XML_TEXT_NODE.
EXAMPLE
This example finds all <item>s with a price attribute that's
greater than 5, and prints out their <name> sub-element and
price attribute.
<$xpath = (xmlTreeNewXPath($doc))>
<$nodes = (xmlTreeXPathExecute($xpath, '//item[@price>5]'))>
<loop $nodes>
<$name = (xmlTreeGetChildrenContent($nodes, 'name'))>
<$price = (xmlTreeGetAttributeContent($nodes, 'price'))>
$name costs $price
</loop>
CAVEATS
In the unusual case that you're XPathing for a namespace declaration
directly (//*/namespace::myprefix), note that the xmlNs
object returned is a copy, and changes made to it will not be
reflected in the original doc (elements and attributes return a
reference in the original doc, and do not have this limitation).
Instead, you can XPath for the element that contains that definition
(//*[namespace::myprefix]), use xmlTreeGetNsDef
to get the namespace object and change it as needed.
SEE ALSOxmlTreeNewXPath,
xmlTreeXPathRegisterNs
xmlTreeXPathSetContext