2011-11-03 20:11:40 +00:00
|
|
|
CssSelector Component
|
|
|
|
=====================
|
|
|
|
|
2011-12-18 13:18:13 +00:00
|
|
|
CssSelector converts CSS selectors to XPath expressions.
|
2011-11-03 20:11:40 +00:00
|
|
|
|
2011-12-18 13:18:13 +00:00
|
|
|
The component only goal is to convert CSS selectors to their XPath
|
|
|
|
equivalents:
|
2011-11-03 20:11:40 +00:00
|
|
|
|
2011-12-18 13:18:13 +00:00
|
|
|
use Symfony\Component\CssSelector\CssSelector;
|
2011-11-03 20:11:40 +00:00
|
|
|
|
2011-12-18 13:18:13 +00:00
|
|
|
print CssSelector::toXPath('div.item > h4 > a');
|
2011-11-03 20:11:40 +00:00
|
|
|
|
2013-06-16 10:03:18 +01:00
|
|
|
HTML and XML are different
|
|
|
|
--------------------------
|
|
|
|
|
2013-06-17 08:15:51 +01:00
|
|
|
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`:
|
2013-06-16 10:03:18 +01:00
|
|
|
|
|
|
|
// disable `HTML` extension:
|
|
|
|
CssSelector::disableHtmlExtension();
|
2013-06-17 08:15:51 +01:00
|
|
|
|
2013-06-16 10:03:18 +01:00
|
|
|
// re-enable `HTML` extension:
|
|
|
|
CssSelector::enableHtmlExtension();
|
|
|
|
|
2013-06-17 08:15:51 +01:00
|
|
|
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.
|
2013-06-16 10:03:18 +01:00
|
|
|
|
2011-11-03 20:11:40 +00:00
|
|
|
Resources
|
|
|
|
---------
|
|
|
|
|
2011-12-18 13:18:13 +00:00
|
|
|
This component is a port of the Python lxml library, which is copyright Infrae
|
|
|
|
and distributed under the BSD license.
|
|
|
|
|
2013-03-23 19:31:06 +00:00
|
|
|
Current code is a port of https://github.com/SimonSapin/cssselect@v0.7.1
|
2012-03-28 14:43:52 +01:00
|
|
|
|
|
|
|
You can run the unit tests with the following command:
|
|
|
|
|
2012-11-09 09:18:50 +00:00
|
|
|
$ cd path/to/Symfony/Component/CssSelector/
|
2013-09-18 08:27:26 +01:00
|
|
|
$ composer.phar install
|
2012-11-09 09:18:50 +00:00
|
|
|
$ phpunit
|