QueryPath\DOMQuery::xpath PHP Метод

xpath() публичный Метод

Most methods in this class support CSS 3 Selectors. Sometimes, though, XPath provides a finer-grained query language. Use this to execute XPath queries. Beware, though. DOMQuery works best on DOM Elements, but an XPath query can return other nodes, strings, and values. These may not work with other QueryPath functions (though you will be able to access the values with {@link get()}).
См. также: find()
Автор: M Butcher
Автор: Xavier Prud'homme
public xpath ( string $query, array $options = [] )
$query string An XPath query.
$options array Currently supported options are: - 'namespace_prefix': And XML namespace prefix to be used as the default. Used in conjunction with 'namespace_uri' - 'namespace_uri': The URI to be used as the default namespace URI. Used with 'namespace_prefix'
    public function xpath($query, $options = array())
    {
        $xpath = new \DOMXPath($this->document);
        // Register a default namespace.
        if (!empty($options['namespace_prefix']) && !empty($options['namespace_uri'])) {
            $xpath->registerNamespace($options['namespace_prefix'], $options['namespace_uri']);
        }
        $found = new \SplObjectStorage();
        foreach ($this->matches as $item) {
            $nl = $xpath->query($query, $item);
            if ($nl->length > 0) {
                for ($i = 0; $i < $nl->length; ++$i) {
                    $found->attach($nl->item($i));
                }
            }
        }
        return $this->inst($found, null, $this->options);
        //$this->setMatches($found);
        //return $this;
    }