2017 © Pedro Peláez
 

library query-path

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

image

arthurkushman/query-path

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  • Wednesday, July 25, 2018
  • by arthurkushman
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 89 Forks
  • 1 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

QueryPath: Find the better way

Scrutinizer Code Quality Build Status Code Intelligence Status codecov License: MIT, (*1)

At A Glance

QueryPath is a jQuery-like library for working with XML and HTML documents in PHP. It now contains support for HTML5 via the HTML5-PHP project., (*2)

Why this lib was forked and recoded

  • Legacy code (repo was left for > 3 years) didn't allow to support new features of PHP>=7.1
  • A lot of DeaDBeaF code like: unused params, unused local variables etc
  • A lot of needless flow structures
  • DRY/KISS/SOLID rules were thrown away when it was developed
  • Minor bugs and fragile functionality

Installation

composer require arthurkushman/query-path 

Gettings Started

Assuming you have successfully installed QueryPath via Composer, you can parse documents like this:, (*3)

// HTML5 (new)
$qp = html5qp("path/to/file.html");

// Legacy HTML via libxml
$qp = htmlqp("path/to/file.html");

// XML or XHTML
$qp = qp("path/to/file.html");

// All of the above can take string markup instead of a file name:
$qp = qp("<hello><world/></hello>")

But the real power comes from chaining. Check out the example below., (*4)

Example Usage

Say we have a document like this:, (*5)

<?xml version="1.0"?>
<table>
  <tr id="row1">
    <td>one</td><td>two</td><td>three</td>
  </tr>
  <tr id="row2">
    <td>four</td><td>five</td><td>six</td>
  </tr>
</table>

And say that the above is stored in the variable $xml. Now we can use QueryPath like this:, (*6)

attr('foo', 'bar');

// Print the contents of the third TD in the second row:
echo qp($xml, '#row2>td:nth(3)')->text();

// Append another row to the XML and then write the
// result to standard output:
qp($xml, 'tr:last')->after('



')->writeXML();

?>

(This example is in examples/at-a-glance.php.), (*7)

With over 60 functions and robust support for chaining, you can accomplish sophisticated XML and HTML processing using QueryPath., (*8)

From there, the main functions you will want to use are qp() (alias of QueryPath::with()) and htmlqp() (alias of QueryPath::withHTML())., (*9)

QueryPath Format Extension

format()

\QueryPath\DOMQuery format(callable $callback [, mixed $args [, $... ]])

A quick example:, (*10)

<root>

_apple_
_orange_
</root>'); $qp->find('div') ->format('strtoupper') ->format('trim', '_') ->format(function ($text) { return '*' . $text . '*'; }); $qp->writeXML();

OUTPUT:, (*11)

<?xml version="1.0"?>
<root>
  <div>*APPLE*</div>
  <div>*ORANGE*</div>
</root>

formatAttr()

\QueryPath\DOMQuery formatAttr(string $name, callable $callback [, mixed $args [, $... ]])

A quick example:, (*12)

<root>' .
        '<item label="_apple_" total="12,345,678" />' .
        '<item label="_orange_" total="987,654,321" />' .
        '</root>');

$qp->find('item')
        ->formatAttr('label', 'trim', '_')
        ->formatAttr('total', 'str_replace[2]', ',', '');

$qp->find('item')->formatAttr('label', function ($value) {
    return ucfirst(strtolower($value));
});

$qp->writeXML();

OUTPUT:, (*13)

<?xml version="1.0"?>
<root>
  <item label="Apple" total="12345678"/>
  <item label="Orange" total="987654321"/>
</root>

The Versions

25/07 2018

dev-master

9999999-dev https://github.com/arthurkushman/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html php7 xslt

23/07 2018

dev-fix_non_dom_node_list_nl

dev-fix_non_dom_node_list_nl https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html xslt

02/08 2016

3.0.5

3.0.5.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html xslt

10/10 2015

3.0.4

3.0.4.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html xslt

23/09 2014

3.0.3

3.0.3.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

03/07 2013

3.x-dev

3.9999999.9999999.9999999-dev https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html xslt

05/06 2013

dev-feature/html5

dev-feature/html5 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

 

css xml jquery html xslt

24/05 2013

3.0.2

3.0.2.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

08/03 2013

3.0.1

3.0.1.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

11/12 2012

3.0.0

3.0.0.0 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

01/09 2012

dev-feature/find-v2

dev-feature/find-v2 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

01/09 2012

3.0.0-alpha3

3.0.0.0-alpha3 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

25/06 2012

3.0.0-alpha2

3.0.0.0-alpha2 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

01/06 2012

3.0.0-alpha1

3.0.0.0-alpha1 https://github.com/technosophos/querypath

HTML/XML querying (CSS 4 or XPath) and processing (like jQuery)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

css xml jquery html xslt

29/02 2012

dev-feature/domquery

dev-feature/domquery https://github.com/technosophos/querypath

HTML/XML querying and processing (like jQuery)

  Sources   Download

MIT-style

The Requires

  • php >=5.2.0

 

css xml jquery html xslt

28/02 2012

2.x-dev

2.9999999.9999999.9999999-dev https://github.com/technosophos/querypath

HTML/XML querying and processing (like jQuery)

  Sources   Download

MIT-style

The Requires

  • php >=5.2.0

 

css xml jquery html xslt

04/02 2012

2.1.2

2.1.2.0 https://github.com/technosophos/querypath

HTML/XML querying and processing (like jQuery)

  Sources   Download

MIT-style

The Requires

  • php >=5.2.0

 

css xml jquery html xslt