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
Lukas Kahwe Smith 6a72b8c6b9 added basic README files for all components
heavily inspired by http://fabien.potencier.org/article/49/what-is-symfony2 and the official Symfony2 documentation
2011-11-03 21:11:40 +01:00

1009 B

CssSelector Component

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 http://codespeak.net/svn/lxml/trunk/src/lxml/cssselect.py@71545

Using CSS selectors is far easier than using XPath.

Its only goal is to convert a CSS selector to its XPath equivalent:

use Symfony\Component\CssSelector\CssSelector;

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

That way, you can just use CSS Selectors with the DomCrawler instead of XPath:

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler();
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');

print $crawler->filter('body > p')->text();

By the way, that's one example of a component (DomCrawler) that relies on another one (CssSelector) for some optional features.

Resources

Unit tests:

https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/CssSelector