PHPackages                             wildhoney/xpath-document - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wildhoney/xpath-document

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wildhoney/xpath-document
========================

Friendlier XPath extension of DOMDocument for those fluent in beloved XPath!

027[1 issues](https://github.com/Wildhoney/XPathDocument/issues)PHP

Since Nov 13Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Wildhoney/XPathDocument)[ Packagist](https://packagist.org/packages/wildhoney/xpath-document)[ RSS](/packages/wildhoney-xpath-document/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

XPathDocument
=============

[](#xpathdocument)

[![](https://camo.githubusercontent.com/4534adbfbff3fd8ccc07d2222fc242743267f010ea09578301a5467de58d7aa2/68747470733a2f2f7472617669732d63692e6f72672f57696c64686f6e65792f42616e7465722e6a732e706e673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/4534adbfbff3fd8ccc07d2222fc242743267f010ea09578301a5467de58d7aa2/68747470733a2f2f7472617669732d63692e6f72672f57696c64686f6e65792f42616e7465722e6a732e706e673f6272616e63683d6d6173746572)

**Bower:** `bower install wildhoney/xpath-document`

Getting Started
---------------

[](#getting-started)

XPathDocument allows you to chain your `query` methods, allowing you to delve deeper into the DOM hierarchy with each iteration.

```
$posts = $xpathDocument->query('//div[@class="posts"]');

foreach ($posts as $post) {
    $comments = $post->query('div[@class="comments"]');
}
```

Each `query` will return an instance of `XPathDocument_Dom_List` – and this class implements `Iterator`, `ArrayAccess` and `Countable`, which gives you lots of useful methods for manipulating the node collection.

[![](https://camo.githubusercontent.com/93921cf4972f221c482534868d0d382724817ff0b2b02c4dd2e593530eb8596c/687474703a2f2f692e696d6775722e636f6d2f4f4d4f4e4563512e706e67)](https://camo.githubusercontent.com/93921cf4972f221c482534868d0d382724817ff0b2b02c4dd2e593530eb8596c/687474703a2f2f692e696d6775722e636f6d2f4f4d4f4e4563512e706e67)

Typically `XPathDocument_Dom_List` will hold a collection of `XPathDocument_Dom_Element` instances – but other instances are possible:

- `XPathDocument_Dom_Element` – generic elements with values and attributes;
- `XPathDocument_Dom_Attr` – specific for node attributes;
- `XPathDocument_Dom_Text` – specific for text values of nodes;

The latter two have a simple `getText` method for returning their values. However, `XPathDocument_Dom_Element` has the greatest flexibility.

Element Instance
----------------

[](#element-instance)

With an instance of `XPathDocument_Dom_Element` you have the following methods:

- `getText` – retrieve the value of the node;
- `getHtml` – retrieve the HTML value of the node;
- `getName` – retrieve the name of the node (`span`, `div`, etc...);
- `getAttribute` – retrieve an attribute by its name;
- `query` – use node as the context for further querying;

Reddit Example
--------------

[](#reddit-example)

Please see the Reddit.com example in the `example/index.php` which will demonstrate how simple it is to crawl websites with `XPathDocument`!

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e2aafb8e02f3f1c6e26f0d6f9194e90e442bf53a920c0b2ca842a49b68fa38f?d=identicon)[Wildhoney](/maintainers/Wildhoney)

---

Top Contributors

[![Wildhoney](https://avatars.githubusercontent.com/u/1528477?v=4)](https://github.com/Wildhoney "Wildhoney (18 commits)")

### Embed Badge

![Health badge](/badges/wildhoney-xpath-document/health.svg)

```
[![Health](https://phpackages.com/badges/wildhoney-xpath-document/health.svg)](https://phpackages.com/packages/wildhoney-xpath-document)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
