2017 © Pedro Peláez
 

library querypath

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

image

querypath/querypath

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

  • Friday, March 17, 2017
  • by technosophos
  • Repository
  • 45 Watchers
  • 773 Stars
  • 1,116,975 Installations
  • PHP
  • 33 Dependents
  • 0 Suggesters
  • 89 Forks
  • 58 Open issues
  • 16 Versions
  • 9 % Grown

The README.md

Use GravityPDF's QueryPath

QueryPath is now updated and maintained by the amazing folks at GravityPDF. https://github.com/GravityPDF/querypath. The version of QueryPath in this repository is no longer maintained. You are encouraged to use GravityPDF's version. -- Matt, Dec. 2022, (*1)

QueryPath: Find your way.

Stability: Maintenance, (*2)

Authors: Matt Butcher (lead), Emily Brand, and many others, (*3)

Website | API Docs | VCS and Issue Tracking | Support List | Developer List | Pear channel |, (*4)

This package is licensed under an MIT license (COPYING-MIT.txt)., (*5)

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

Gettings Started

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

require_once "vendor/autoload.php";

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

Example Usage

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

<?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:, (*10)

attr('foo', 'bar');

// Print the contents of the third TD in the second row:
print 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.), (*11)

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

QueryPath Installers

The preferred method of installing QueryPath is via Composer., (*13)

You can also download the package from GitHub., (*14)

Composer (Preferred)

To add QueryPath as a library in your project, add this to the 'require' section of your composer.json:, (*15)

{
  "require": {
    "querypath/QueryPath": ">=3.0.0"
  }
}

The run php composer.phar install in that directory., (*16)

To stay up to date on stable code, you can use dev-master instead of >=3.0.0., (*17)

Manual Install

You can either download a stable release from the GitHub Tags page or you can use git to clone this repository and work from the code., (*18)

Including QueryPath

As of QueryPath 3.x, QueryPath uses the Composer autoloader if you installed with composer:, (*19)

<?php
require 'vendor/autoload.php';
?>

Without Composer, you can include QueryPath like this:, (*20)

<?php
require 'QueryPath/src/qp.php';
?>

QueryPath can also be compiled into a Phar and then included like this:, (*21)

<?php
require 'QueryPath.phar';
?>

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

The Versions

17/03 2017

dev-master

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

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