From e44ba25714a285b19d577b70b1e75a61cde5ebb8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Oct 2010 01:26:24 +0000 Subject: [PATCH] ENHANCEMENT Added CSSContentParser->getByXpath() (from r105126) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112440 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/CSSContentParser.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dev/CSSContentParser.php b/dev/CSSContentParser.php index 718b5c59d..78ff67f0a 100644 --- a/dev/CSSContentParser.php +++ b/dev/CSSContentParser.php @@ -53,16 +53,33 @@ class CSSContentParser extends Object { /** * Returns a number of SimpleXML elements that match the given CSS selector. - * Currently the selector engine only supports querying by tag, id, and classs + * Currently the selector engine only supports querying by tag, id, and class. + * See {@link getByXpath()} for a more direct selector syntax. + * + * @param String $selector + * @return SimpleXMLElement */ function getBySelector($selector) { $xpath = $this->selector2xpath($selector); - return $this->simpleXML->xpath($xpath); + return $this->getByXpath($xpath); } + /** + * Allows querying the content through XPATH selectors. + * + * @param String $xpath SimpleXML compatible XPATH statement + * @return SimpleXMLElement|false + */ + function getByXpath($xpath) { + return $this->simpleXML->xpath($xpath); + } + /** * Converts a CSS selector into an equivalent xpath expression. - * Currently the selector engine only supports querying by tag, id, and classs + * Currently the selector engine only supports querying by tag, id, and class. + * + * @param String $selector See {@link getBySelector()} + * @return String XPath expression */ function selector2xpath($selector) { $parts = preg_split('/\\s+/', $selector); @@ -85,4 +102,5 @@ class CSSContentParser extends Object { return $xpath; } + } \ No newline at end of file