/** * Gets nodes from a list by a given factor. * * @param array $nodes List of DOMNode objects * @param CssParserModelFactor $factor Factor object * * @return array of DOMElement objects */ private function _getNodesByFactor($nodes, $factor) { $ret = array(); foreach ($nodes as $node) { $items = $factor->filter($node); $ret = Dom::mergeNodes($ret, $items); } return $ret; }
/** * Is the next thing a selectorList? * * A selectorList is one or more css selectors separated by commas. * * For example: * ``` * div > div.class div#id, div > p, pre * ``` * * In the above example, the following strings are terms: * ``` * div > div.class div * div > p * pre * ``` * * @return ArrayObject of DOMElement objects */ protected function selectorList() { $nodes = array(); do { if (!($selector = $this->is("selector"))) { // throw new TextParserException("Invalid expression", $this); break; } $nodes = Dom::mergeNodes($nodes, $selector->filter($this->_node)); } while ($this->eq(",")); return new ArrayObject(Dom::sortNodes($nodes)); }
/** * Finds nodes. * * This function is identical to 'query' except it uses XPath expressions, instead of * CSS selectors. * * @param string $expression XPath expression * * @return DomNode */ public function xpath($expression) { $elements = array(); foreach ($this->elements as $element) { $xpath = new DOMXPath($element->ownerDocument); $items = $xpath->query($expression, $element); // converts DOMNodeList to array $nodes = array(); foreach ($items as $item) { array_push($nodes, $item); } $elements = Dom::mergeNodes($elements, $nodes); } $node = new DomNode(); $node->document = $this->document; $node->elements = $elements; return $node; }