mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added CSSContentParser->getByXpath() (from r105126)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112440 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8d07a8eccc
commit
e44ba25714
@ -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->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user