2017 © Pedro Peláez
 

library cssxpath

Convert CSS selectors to XPath queries.

image

phpgt/cssxpath

Convert CSS selectors to XPath queries.

  • Monday, July 30, 2018
  • by g105b
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The 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., (*1)


Build status Code quality Code coverage Current version PHP.Gt/CssXPath documentation , (*2)

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., (*3)

$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., (*4)

The Versions

30/07 2018

dev-master

9999999-dev

Convert CSS selectors to XPath queries.

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

27/04 2018

dev-start

dev-start

Convert CSS selectors to XPath queries.

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires