/** * Perform a CSS selector query * * @param string $query * @return Zend_Dom_Query_Result */ public function query($query) { $xpathQuery = Zend_Dom_Query_Css2Xpath::transform($query); return $this->queryXpath($xpathQuery, $query); }
} else { $extract_pattern = implode(' ', $extract_pattern); $auto_extract = false; } // Convert CSS to XPath // Borrowed from Symfony's cssToXpath() function: https://github.com/fabpot/symfony/blob/master/src/Symfony/Component/CssSelector/Parser.php // (Itself based on Python's lxml library) if (preg_match('#^\\w+\\s*$#u', $extract_pattern, $match)) { $extract_pattern = '//' . trim($match[0]); } elseif (preg_match('~^(\\w*)#(\\w+)\\s*$~u', $extract_pattern, $match)) { $extract_pattern = sprintf("%s%s[@id = '%s']", '//', $match[1] ? $match[1] : '*', $match[2]); } elseif (preg_match('#^(\\w*)\\.(\\w+)\\s*$#u', $extract_pattern, $match)) { $extract_pattern = sprintf("%s%s[contains(concat(' ', normalize-space(@class), ' '), ' %s ')]", '//', $match[1] ? $match[1] : '*', $match[2]); } else { // if the patterns above do not match, invoke Zend's CSS to Xpath function $extract_pattern = Zend_Dom_Query_Css2Xpath::transform($extract_pattern); } } else { $extract_pattern = false; } ///////////////////////////////////// // Check for valid format // (stick to RSS (or RSS as JSON) for the time being) ///////////////////////////////////// if (isset($_GET['format']) && $_GET['format'] == 'json') { $format = 'json'; } else { $format = 'rss'; } ////////////////////////////////// // Check for cached copy
/** * @group ZF-9764 */ public function testIdSelectorWithLeadingAsterix() { $test = Zend_Dom_Query_Css2Xpath::transform('*#id'); $this->assertEquals("//*[@id='id']", $test); }
/** * @group ZF-8006 */ public function testShouldAllowWhitespaceInDescendentSelectorExpressions() { $test = Zend_Dom_Query_Css2Xpath::transform('child > leaf'); $this->assertEquals("//child/leaf", $test); }
public function testShouldAllowContentMatchingOfArbitraryAttributes() { $test = Zend_Dom_Query_Css2Xpath::transform('div[foo*="bar"]'); $this->assertEquals("//div[contains(@foo, 'bar')]", $test); }
/** * Query the document using a CSS selector. * @param string $selector The CSS selector. * @return array The matching elements. */ public function select($selector) { $query = Zend_Dom_Query_Css2Xpath::transform($selector); return $this->xpath($query); }