Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[READ-ONLY] Subtree split of the Symfony CssSelector Component -- clone into Symfony/Component/ (master at symfony/symfony)

Merge branch '2.4'

* 2.4:
  fixed types in phpdocs
  fixed types in phpdocs

latest commit 97a17ebdc9
Fabien Potencier fabpot authored
Octocat-spinner-32 Exception [CssSelector] fully rewritted component March 23, 2013
Octocat-spinner-32 Node fixed CS October 30, 2013
Octocat-spinner-32 Parser Merge branch '2.3' into 2.4 April 16, 2014
Octocat-spinner-32 Tests Fix libxml_use_internal_errors and libxml_disable_entity_loader usage March 26, 2014
Octocat-spinner-32 XPath fixed types in phpdocs April 16, 2014
Octocat-spinner-32 .gitignore Added missing files .gitignore July 21, 2013
Octocat-spinner-32 [CssSelector] added CHANGELOG April 26, 2012
Octocat-spinner-32 CssSelector.php [CssSelector] fixed BC break March 23, 2013
Octocat-spinner-32 LICENSE update year on licenses January 07, 2014
Octocat-spinner-32 Merge branch '2.2' into 2.3 September 19, 2013
Octocat-spinner-32 composer.json updated version to 2.5 November 24, 2013
Octocat-spinner-32 phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests November 09, 2012

CssSelector Component

CssSelector converts CSS selectors to XPath expressions.

The component only goal is to convert CSS selectors to their XPath equivalents:

use Symfony\Component\CssSelector\CssSelector;

print CssSelector::toXPath('div.item > h4 > a');

HTML and XML are different

The CssSelector component comes with an HTML extension which is enabled by default. If you need to use this component with XML documents, you have to disable this HTML extension. That's because, HTML tag & attribute names are always lower-cased, but case-sensitive in XML:

// disable `HTML` extension:

// re-enable `HTML` extension:

When the HTML extension is enabled, tag names are lower-cased, attribute names are lower-cased, the following extra pseudo-classes are supported: checked, link, disabled, enabled, selected, invalid, hover, visited, and the lang() function is also added.


This component is a port of the Python lxml library, which is copyright Infrae and distributed under the BSD license.

Current code is a port of

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/CssSelector/
$ composer.phar install
$ phpunit
Something went wrong with that request. Please try again.