2017 © Pedro Peláez
 

library css-xpath

Search html via CSS selector or convert css selector to xpath

image

bdk/css-xpath

Search html via CSS selector or convert css selector to xpath

  • Thursday, February 1, 2018
  • by brad.kent
  • Repository
  • 1 Watchers
  • 1 Stars
  • 459 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 46 % Grown

The README.md

CssXpath

  • Convert CSS selector to XPath
  • Query HTML string (or \DOMDocument) by CSS selector
  • Provide PHPUnit Assertions (once provided by PHPUnit)

No Dependencies Supported PHP versions Build Status Maintainability Coverage, (*1)

Installation

composer require bdk/css-xpath

Usage

CSS to XPath

\bdk\CssXpath\CssXpath::cssToXpath('ul > li:first-child');  // returns '//ul/li[1]'

Query DOM/HTML

Example:, (*2)

$html = <<<HTML
<div id="article" class="block large">


Article Name

Contents of article, (*3)

  • One
  • Two
  • Three
  • Four
  • Five
</div> HTML; // use static method var_dump(\bdk\CssXpath\CssSelect::select($html, 'ul > li:last-child [href]')); // or create and use an instance $cssSelect = new \bdk\CssXpath\CssSelect($html); $found = $cssSelect->select('ul > li:last-child [href]');

Output:, (*4)

array (size=1)
  0 =>
    array (size=3)
      'name' => string 'a' (length=1)
      'attributes' =>
        array (size=1)
          'href' => string '#' (length=1)
      'innerHTML' => string 'Five' (length=4)

Pass a last argument of true, to return a \DOMNodeList object instead of an array, (*5)

PHPUnit

bdk\CssXpath\DOMTestCase extends \PHPUnit\Framework\TestCase and provids 3 assertions:, (*6)

  • assertSelectCount($selector, $count, $actual, $message = '')
  • assertSelectRegExp($selector, $pattern, $count, $actual, $message = '')
  • assertSelectEquals($selector, $content, $count, $actual, $message = '')

These assertions were originally provided with PHPUnit 3.3, but removed with PHPUnit 5.0, (*7)

The Versions

01/02 2018

dev-master

9999999-dev http://github.com/bkdotcom/CssXpath

Search html via CSS selector or convert css selector to xpath

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xpath

01/02 2018

v1.0

1.0.0.0 http://github.com/bkdotcom/CssXpath

Search html via CSS selector or convert css selector to xpath

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xpath