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 7e4b4a7ebb Merge branch '2.4'
* 2.4:
  Lower mbstring dependency
  [Console]Improve formatter for double-width character
  Lower mbstring dep, remove it for Yaml and CssSelector components
  [Security] Add check for supported attributes in AclVoter
  [Form] Fixed TrimListenerTest as of PHP 5.5
  Added more IDE links
  [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface
  [Security] fixed wrong PHPDoc of the TokenGeneratorInterface
  [Finder] fixed typehint of the Finder::addAdapter() method
  [TwigBridge][Transchoice] set %count% from the current context.
  [DependencyInjection] Fix travis unit tests
  Update PHPUnit before run
  [Validator] fixed wrong test
  [WebProfilerBundle] added test case for #10773
  [WebProfilerBundle] fixed profiler homepage, fixed #10806
  [WebProfilerBundle] Added test case for #10806
  changed travis to run on the nightly builds of HHVM until everything gets stable
  Fixed issue #5427
  Allow URLs that don't contain a path

Conflicts:
	.travis.yml
	src/Symfony/Component/Console/Application.php
2014-05-12 11:28:39 +02:00
..
Exception [CssSelector] fully rewritted component 2013-03-23 19:04:09 +01:00
Node fixed CS 2013-10-30 09:30:20 +01:00
Parser Merge branch '2.3' into 2.4 2014-05-12 11:27:48 +02:00
Tests Fix libxml_use_internal_errors and libxml_disable_entity_loader usage 2014-03-26 08:21:50 +01:00
XPath fixed types in phpdocs 2014-04-16 12:30:19 +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 updated version to 2.5 2013-11-24 21:17:07 +01:00
CssSelector.php [CssSelector] fixed BC break 2013-03-23 20:31:06 +01:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
README.md Merge branch '2.2' into 2.3 2013-09-19 11:45:20 +02: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 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