Permalink
Browse files

ENHANCEMENT Added CSSContentParser->getByXpath() (from r105126)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112440 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 8d07a8e commit e44ba25714a285b19d577b70b1e75a61cde5ebb8 @chillu chillu committed Oct 15, 2010
Showing with 21 additions and 3 deletions.
  1. +21 −3 dev/CSSContentParser.php
View
24 dev/CSSContentParser.php
@@ -53,16 +53,33 @@ function __construct($content) {
/**
* 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 @@ function selector2xpath($selector) {
return $xpath;
}
+
}

0 comments on commit e44ba25

Please sign in to comment.