FluentDOM\Xpath::evaluate PHP Method

evaluate() public method

The main difference to DOMXpath::evaluate() is the handling of the third argument. Namespace registration can be changed using the property and is disabled by default.
public evaluate ( string $expression, DOMNode $contextNode = NULL, null | boolean $registerNodeNS = NULL ) : string | float | boolean | DOMNodeList
$expression string
$contextNode DOMNode
$registerNodeNS null | boolean
return string | float | boolean | DOMNodeList
    public function evaluate($expression, \DOMNode $contextNode = NULL, $registerNodeNS = NULL)
    {
        $registerNodeNS = NULL === $registerNodeNS ? $this->_registerNodeNamespaces : $registerNodeNS;
        return parent::evaluate($expression, $contextNode, (bool) $registerNodeNS);
    }

Usage Example

Example #1
0
 /**
  * @param \DOMElement $node
  * @param \stdClass|array $attributes
  * @param Xpath $xpath
  * @return array
  */
 private function getNodesArray(\DOMElement $node, $attributes, $xpath)
 {
     $result = [];
     foreach ($attributes as $name => $value) {
         $child = new \stdClass();
         $child->{$name} = $value;
         $result[] = $child;
     }
     foreach ($xpath->evaluate('*|text()[normalize-space(.) != ""]', $node) as $childNode) {
         /** @var \DOMElement|\DOMText|\DOMCdataSection $childNode */
         if ($childNode instanceof \DOMElement) {
             $child = new \stdClass();
             $child->{$childNode->nodeName} = $this->getNodes($childNode);
             $result[] = $child;
         } elseif (!$childNode->isWhitespaceInElementContent()) {
             $result[] = $childNode->nodeValue;
         }
     }
     return $result;
 }
All Usage Examples Of FluentDOM\Xpath::evaluate