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/README.md
Fabien Potencier 88cef41560 Merge branch '2.2' into 2.3
* 2.2:
  Fix some annotates
  [FrameworkBundle] made sure that the debug event dispatcher is used everywhere
  [HttpKernel] remove unneeded strtoupper
  updated the composer install command to reflect changes in Composer

Conflicts:
	src/Symfony/Component/Console/Application.php
	src/Symfony/Component/Console/Command/Command.php
	src/Symfony/Component/Console/Input/InputDefinition.php
	src/Symfony/Component/CssSelector/Node/CombinedSelectorNode.php
	src/Symfony/Component/Form/Form.php
	src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php
	src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php
	src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php
	src/Symfony/Component/Locale/Locale.php
	src/Symfony/Component/Locale/README.md
	src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php
2013-09-19 11:45:20 +02:00

1.4 KiB

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 lxml library, which is copyright Infrae and distributed under the BSD license.

Current code is a port of https://github.com/SimonSapin/cssselect@v0.7.1

You can run the unit tests with the following command:

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