Alexandre Alapetite 37c8f1f466 CSSXPath 1.5.0 (#8642) 4 дней назад
..
src 37c8f1f466 CSSXPath 1.5.0 (#8642) 4 дней назад
LICENSE d6fd78b968 Allow CssXPath updates with composer (#4368) 3 лет назад
README.md 37c8f1f466 CSSXPath 1.5.0 (#8642) 4 дней назад
phpcs.xml 37c8f1f466 CSSXPath 1.5.0 (#8642) 4 дней назад

README.md

Translate CSS selectors to XPath queries.

A lightweight and dependency free CSS to XPath translator. This repository is used to bring modern DOM functionality like querySelectorAll() to PHP in the PHP.Gt/Dom project.


<img src="https://badge.status.php.gt/cssxpath-build.svg" alt="Build status" />

<img src="https://badge.status.php.gt/cssxpath-quality.svg" alt="Code quality" />

<img src="https://badge.status.php.gt/cssxpath-coverage.svg" alt="Code coverage" />

<img src="https://badge.status.php.gt/cssxpath-version.svg" alt="Current version" />

<img src="https://badge.status.php.gt/cssxpath-docs.svg" alt="PHP.Gt/CssXPath documentation" />

Example usage

use Gt\CssXPath\Translator;

$html = <<<HTML
<form>
	<label>
		Name
		<input name="name" />
	</label>
	<label>
		Code:
		<input name="code" />
	</label>
	<button name="do" value="submit">Submit code</button>
</form>
HTML;

$document = new DOMDocument();
$document->loadHTML($html);

$xpath = new DOMXPath($document);
$inputElementList = $xpath->query(new Translator("form>label>input"));

Using this library with XML Documents

To correctly work with XML documents, where the attributes are case-sensitive, pass false to the htmlMode property of the constructor.

$translator = new Translator("[data-FOO='bar']", htmlMode: false);

It's perhaps worth noting that for XML-style matching to work, you must load the document content with DOMDocument->load/DOMDocument->loadXML instead of DOMDocument->loadHTMLFile/DOMDocument->loadHTML, as the HTML loading methods automatically convert the tags and attribute names to lowercase. This is handled automatically when using PHP.Gt/Dom.

Proudly sponsored by

JetBrains Open Source sponsorship program

JetBrains logo.