FluentDOM\Nodes::xpath PHP Method

xpath() public method

public xpath ( string $expression = NULL, DOMNode $contextNode = NULL ) : Xpath | DOMNodeList | float | string
$expression string
$contextNode DOMNode
return Xpath | DOMNodeList | float | string
    public function xpath($expression = NULL, $contextNode = NULL)
    {
        if (isset($expression)) {
            return $this->getXpath()->evaluate($expression, $contextNode);
        } else {
            return $this->getXpath();
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Fetch the nodes for the provided context node. If $context
  * ist NULL the document context is used.
  *
  * @throws \InvalidArgumentException
  * @param string $expression
  * @param \DOMNode $context
  * @param int $options
  * @return array|bool|\DOMNodeList|float|string
  */
 private function fetchNodes($expression, \DOMNode $context = NULL, $options = 0)
 {
     $nodes = $this->_nodes->xpath($expression, $context);
     if (!$nodes instanceof \DOMNodeList) {
         throw new \InvalidArgumentException('Given selector/expression did not return a node list.');
     }
     $nodes = iterator_to_array($nodes);
     if (Constraints::hasOption($options, self::REVERSE)) {
         return array_reverse($nodes, FALSE);
     }
     return $nodes;
 }