W3cubDocs

/Symfony 2.7

Symfony\Component\CssSelector\XPath\Translator

class Translator implements TranslatorInterface

XPath expression translator interface.

This component is a port of the Python cssselector library, which is copyright Ian Bicking, see https://github.com/SimonSapin/cssselect.

Methods

__construct(ParserInterface $parser = null)

Constructor.

static string getXpathLiteral(string $element)
XPathExpr cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::')

Translates a CSS selector to an XPath expression.

XPathExpr selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::')

Translates a parsed selector node to an XPath expression

Translator registerExtension(ExtensionInterface $extension)

Registers an extension.

ExtensionInterface getExtension(string $name)
Translator registerParserShortcut(ParserInterface $shortcut)

Registers a shortcut parser.

XPathExpr nodeToXPath(NodeInterface $node)
XPathExpr addCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath)
XPathExpr addFunction(XPathExpr $xpath, FunctionNode $function)
XPathExpr addPseudoClass(XPathExpr $xpath, string $pseudoClass)
XPathExpr addAttributeMatching(XPathExpr $xpath, string $operator, string $attribute, string $value)

Details

public __construct(ParserInterface $parser = null)

Constructor.

Parameters

ParserInterface $parser

static public string getXpathLiteral(string $element)

Parameters

string $element

Return Value

string

public XPathExpr cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::')

Translates a CSS selector to an XPath expression.

Parameters

string $cssExpr
string $prefix

Return Value

XPathExpr

public XPathExpr selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::')

Translates a parsed selector node to an XPath expression

Parameters

SelectorNode $selector
string $prefix

Return Value

XPathExpr

public Translator registerExtension(ExtensionInterface $extension)

Registers an extension.

Parameters

ExtensionInterface $extension

Return Value

Translator

public ExtensionInterface getExtension(string $name)

Parameters

string $name

Return Value

ExtensionInterface

Exceptions

ExpressionErrorException

public Translator registerParserShortcut(ParserInterface $shortcut)

Registers a shortcut parser.

Parameters

ParserInterface $shortcut

Return Value

Translator

public XPathExpr nodeToXPath(NodeInterface $node)

Parameters

NodeInterface $node

Return Value

XPathExpr

Exceptions

ExpressionErrorException

public XPathExpr addCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath)

Parameters

string $combiner
NodeInterface $xpath
NodeInterface $combinedXpath

Return Value

XPathExpr

Exceptions

ExpressionErrorException

public XPathExpr addFunction(XPathExpr $xpath, FunctionNode $function)

Parameters

XPathExpr $xpath
FunctionNode $function

Return Value

XPathExpr

Exceptions

ExpressionErrorException

public XPathExpr addPseudoClass(XPathExpr $xpath, string $pseudoClass)

Parameters

XPathExpr $xpath
string $pseudoClass

Return Value

XPathExpr

Exceptions

ExpressionErrorException

public XPathExpr addAttributeMatching(XPathExpr $xpath, string $operator, string $attribute, string $value)

Parameters

XPathExpr $xpath
string $operator
string $attribute
string $value

Return Value

XPathExpr

Exceptions

ExpressionErrorException

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Component/CssSelector/XPath/Translator.html