public static function xpathQuery(DOMDocument $document, $query, $returnFirst = true)
    {
        $xpath = new DOMXPath($document);
        $entries = $xpath->query($query);

        if ($entries->length) {
            return $returnFirst ? $entries->item(0) : $entries;
        }
    }
public static function xpathQuery(DOMDocument $document, $query, $returnFirst = true)
    {
        $xpath = new DOMXPath($document);
        $entries = $xpath->query($query);

        if ($entries->length) {
            return $returnFirst ? $entries->item(0) : $entries;
        }
    }
public static function xpathQuery ( DOMDocument $ document , $ query , $ returnFirst = true ) { $ xpath = new DOMXPath ( $ document ) ; $ entries = $ xpath -> query ( $ query ) ; if ( $ entries -> length ) { return $ returnFirst ? $ entries -> item ( 0 ) : $ entries ; } }
Search and return the first element matching with a xpath

@param DOMDocument $document
@param string      $query
@param bool        $returnFirst

@return DOMElement|DOMNodeList|null
Search and return the first element matching with a xpath