This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/CssSelector
Fabien Potencier e13373ec11 Merge branch '2.6' into 2.7
* 2.6:
  [DebugBundle] Allow alternative destination for dumps
  [DebugBundle] Use output mechanism of dumpers instead of echoing
  [DebugBundle] Always collect dumps
  Fix tests in HHVM
  CS: Pre incrementation/decrementation should be used if possible

Conflicts:
	src/Symfony/Component/Finder/Expression/Glob.php
2015-05-15 15:33:16 +02:00
..
Exception [2.3] Static Code Analysis for Components 2015-03-21 18:48:06 +01:00
Node Merge branch '2.5' into 2.6 2014-12-30 10:04:52 +01:00
Parser Merge branch '2.3' into 2.6 2015-04-18 17:02:51 +02:00
Tests Merge branch '2.3' into 2.6 2015-03-22 17:55:57 +01:00
XPath CS: Pre incrementation/decrementation should be used if possible 2015-04-07 19:54:22 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [CssSelector] added CHANGELOG 2012-04-26 22:11:05 +02:00
composer.json Merge branch '2.6' into 2.7 2015-05-02 17:21:08 +02:00
CssSelector.php Use the correct cssselect library name in docblocks. 2014-12-26 23:22:03 +01:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
phpunit.xml.dist [2.3] require-dev PHPUnit bridge 2015-02-24 11:24:26 +01:00
README.md renamed composer.phar to composer to be consistent with the Symfony docs 2015-02-08 08:41:14 +01:00

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:
CssSelector::disableHtmlExtension();

// re-enable `HTML` extension:
CssSelector::enableHtmlExtension();

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.

Resources

This component is a port of the Python cssselect library v0.7.1, which is distributed under the BSD license.

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/CssSelector/
$ composer install
$ phpunit