PHPackages                             fluentdom/fluentdom - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. fluentdom/fluentdom

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

fluentdom/fluentdom
===================

A fluent api for the php dom extension.

8.0.0(5y ago)337306.9k↓19.2%20[10 issues](https://github.com/ThomasWeinert/FluentDOM/issues)17MITPHPPHP ~7.2 || ~8.0

Since May 29Pushed 2y ago13 watchersCompare

[ Source](https://github.com/ThomasWeinert/FluentDOM)[ Packagist](https://packagist.org/packages/fluentdom/fluentdom)[ Docs](http://fluentdom.org)[ RSS](/packages/fluentdom-fluentdom/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (36)Used By (17)

FluentDOM
=========

[](#fluentdom)

[![CI](https://github.com/ThomasWeinert/FluentDOM/actions/workflows/ci.yml/badge.svg)](https://github.com/ThomasWeinert/FluentDOM/actions/workflows/ci.yml)

[![License](https://camo.githubusercontent.com/8d228ea5010eeef3ffd3fed2e008f7c7ab495367875b710b938026c8440f809d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666c75656e74646f6d2f666c75656e74646f6d2e737667)](http://opensource.org/licenses/mit-license.php)[![Total Downloads](https://camo.githubusercontent.com/b7576d2ab61904b735e96cd5e4e834428527e59efd1bd42bbf4c5d22b4dea04f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c75656e74646f6d2f666c75656e74646f6d2e737667)](https://packagist.org/packages/fluentdom/fluentdom)[![Latest Stable Version](https://camo.githubusercontent.com/55f4b8063d8028c2d5ca55c6ed2f16155de1f8c6e5220352aefa0f3aba314aef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c75656e74646f6d2f666c75656e74646f6d2e737667)](https://packagist.org/packages/fluentdom/fluentdom)[![Latest Unstable Version](https://camo.githubusercontent.com/ef2b3e5e0d3eb80552c07b938c2c310c2d4ad5aa02e3874af89771dfbc71a140/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f666c75656e74646f6d2f666c75656e74646f6d2e737667)](https://packagist.org/packages/fluentdom/fluentdom)

Copyright: 2009-2018 [FluentDOM Contributors](https://github.com/ThomasWeinert/FluentDOM/graphs/contributors)
License: [The MIT License](http://www.opensource.org/licenses/mit-license.php)

FluentDOM provides extended XML handling classes for PHPs DOM, XMLReader and XMLWriter. Additionally, it contains a easy to use jQuery like, fluent interface for DOM.

Here are loaders and serializers for different formats like JSON, YAML, JsonML and others. More (like HTML5) can be installed as additional packages.

FluentDOM is a test driven project. We write tests before and during the development. You will find the PHPUnit tests in the `tests/` subdirectory.

Table Of Contents
-----------------

[](#table-of-contents)

- Examples
- Support
- Requirements
- Packagist
- Usage
- Backwards Compatibility Breaks

Examples
--------

[](#examples)

Many examples can be found in the `examples/` subdirectory. Here are some for an initial impression:

### Read All Links in a HTML File

[](#read-all-links-in-a-html-file)

```
$document = FluentDOM::load(
  $htmlFile,
  'text/html',
  [FluentDOM\Loader\Options::ALLOW_FILE => TRUE]
);
foreach ($document('//a[@href]') as $a) {
  $links[] = [
    'caption' => (string)$a,
    'href' => $a['href']
  ];
}
var_dump($links);
```

### Create a Select From an Array

[](#create-a-select-from-an-array)

```
$_ = FluentDOM::create();
$_->formatOutput = TRUE;
echo $_(
  'select',
  ['name' => 'example'],
  $_->each(
    ['One', 'Two', 'Three'],
    function($text, $index) use ($_) {
      return $_('option', ['value' => $index], $text);
    }
  )
)->document->saveHTML();
```

### Read Large XML Files (FluentDOM 6.2)

[](#read-large-xml-files-fluentdom-62)

```
$reader = new FluentDOM\XMLReader();
$reader->open('sitemap.xml');
$reader->registerNamespace('s', 'http://www.sitemaps.org/schemas/sitemap/0.9');

foreach (new FluentDOM\XMLReader\SiblingIterator($reader, 's:url') as $url) {
  /** @var FluentDOM\DOM\Element $url */
  var_dump(
    [
      'location' => $url('string(s:loc)'),
      'updated' => $url('string(s:lastmod)')
    ]
  );
}
```

Support
-------

[](#support)

The [wiki](https://github.com/ThomasWeinert/FluentDOM/wiki) provides information and usage examples.

If you find a bug or have a feature request please report it in the [issue tracker](https://github.com/ThomasWeinert/FluentDOM/issues).

You can check out the [![Gitter chat](https://camo.githubusercontent.com/049d236e60faaa82ca4588c492eaf366d0b402e33cd0c6612f4eecf6342edcdd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e2d2d636861742d626c75652e737667)](https://gitter.im/ThomasWeinert/FluentDOM), too.

Be ware that the release packages (downloads) do not include the examples or tests. They are not needed to use the library. If you clone the repository, they will be included.

### Security Issues

[](#security-issues)

If you find a bug that has security implications, you can send an email directly to `thomas@weinert.info`.

Requirements
------------

[](#requirements)

### PHP

[](#php)

- PHP &gt;= 7.0
- ext/dom
- Optional
    - ext/xmlreader
    - ext/xmlwriter

FluentDOM needs at least PHP 7.0 and the DOM extension. For some features additional extensions might be needed, like ext/json to load JSON strings.

To use the extended XMLReader/XMLWriter you will need the respective PHP extensions, of course.

### HHVM

[](#hhvm)

FluentDOM 5.2 and later requires HHVM 3.5.

FluentDOM 4.0 to 5.1 work with HHVM 3.3 but it was limited. If you like to use HHVM it is strongly suggest to use newer releases.

FluentDOM 7.0 and later has not support for HHVM any more.

Packagist
---------

[](#packagist)

FluentDOM is available on [Packagist.org](https://packagist.org/packages/fluentdom/fluentdom), just add the dependency to your composer.json.

```
{
  "require": {
    "fluentdom/fluentdom": "^7.0"
  }
}
```

Usage
-----

[](#usage)

The following examples load the sample.xml file, look for tags &lt;h1&gt; with the attribute "id" that has the value "title", set the content of these tags to "Hello World" and output the manipulated document.

### Extended DOM (FluentDOM &gt;= 5.2)

[](#extended-dom-fluentdom--52)

Using the `FluentDOM\Document` class:

```
$fd = FluentDOM::load('sample.xml');
foreach ($fd('//h1[@id = "title"]') as $node) {
  $node->nodeValue = 'Hello World!';
}

echo $fd->saveXml();
```

### jQuery Style API

[](#jquery-style-api)

Using the `FluentDOM\Query` class:

```
echo FluentDOM('sample.xml')
  ->find('//h1[@id = "title"]')
  ->text('Hello World!');
```

#### CSS Selectors

[](#css-selectors)

If you install a CSS selector to Xpath translation library into a project, you can use the `FluentDOM::QueryCss()` function. It returns a `FluentDOM\Query` instance supporting CSS 3 selectors.

```
$fd = FluentDOM::QueryCss('sample.xml')
  ->find('h1#title')
  ->text('Hello World!');
```

Read more about it in the [Wiki](https://github.com/ThomasWeinert/FluentDOM/wiki/CSS-Selectors)

### Creating XML

[](#creating-xml)

New features in FluentDOM make it easy to create XML, even XML with namespaces. Basically you can register XML namespaces on the document and methods without direct namespace support (like `createElement()`) will resolve the namespace and call the namespace aware variant (like `createElementNS()`).

Check the Wiki for an [example](https://github.com/ThomasWeinert/FluentDOM/wiki/Creating-XML-with-Namespaces-%28Atom%29).

Backwards Compatibility Breaks
------------------------------

[](#backwards-compatibility-breaks)

### From 6.2 to 7.0

[](#from-62-to-70)

The minimum required PHP version now is 7.0. HHVM is not supported any more. Scalar type hints and return types were added.

Moved the extended DOM classes into the `FluentDOM\DOM` namespace. (`FluentDOM\Document` -&gt; `FluentDOM\DOM\Document`). `FluentDOM\Nodes\Creator` was moved to `FluentDOM\Creator`. Several internal classes were moved into a `FluentDOM\Utiltity`namespace.

`FluentDOM\Query::get()` now return a `DOMNode`is the position was provided, not an array any more.

`FluentDOM\DOM\Element::find()` was removed, use `FluentDOM($element)->find()`.

[Previous BC breaks](https://github.com/ThomasWeinert/FluentDOM/wiki/Backwards-Compatibility) are documented in the Wiki.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 90.9% 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.

###  Release Activity

Cadence

Every ~78 days

Recently: every ~222 days

Total

33

Last Release

1856d ago

Major Versions

4.1.4 → 5.0.0-RC32014-06-22

4.1.5 → 5.0.02014-07-31

5.3.0 → 6.0.02016-12-22

6.2.0 → 7.0.02017-10-01

7.4.0 → 8.0.02021-04-18

PHP version history (5 changes)5.0.0-RC1PHP &gt;=5.4.0

4.1.3PHP &gt;=5.2.0

6.0.0PHP &gt;=5.6.0

7.0.0PHP &gt;=7.0

8.0.0PHP ~7.2 || ~8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/236825?v=4)[Thomas Weinert](/maintainers/ThomasWeinert)[@ThomasWeinert](https://github.com/ThomasWeinert)

---

Top Contributors

[![ThomasWeinert](https://avatars.githubusercontent.com/u/236825?v=4)](https://github.com/ThomasWeinert "ThomasWeinert (1475 commits)")[![lapistano](https://avatars.githubusercontent.com/u/95115?v=4)](https://github.com/lapistano "lapistano (127 commits)")[![tobyS](https://avatars.githubusercontent.com/u/187140?v=4)](https://github.com/tobyS "tobyS (8 commits)")[![sebastianbergmann](https://avatars.githubusercontent.com/u/25218?v=4)](https://github.com/sebastianbergmann "sebastianbergmann (2 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (2 commits)")[![thewilkybarkid](https://avatars.githubusercontent.com/u/1784740?v=4)](https://github.com/thewilkybarkid "thewilkybarkid (2 commits)")[![zealotrunner](https://avatars.githubusercontent.com/u/534380?v=4)](https://github.com/zealotrunner "zealotrunner (1 commits)")[![ktomk](https://avatars.githubusercontent.com/u/352517?v=4)](https://github.com/ktomk "ktomk (1 commits)")[![noels](https://avatars.githubusercontent.com/u/546980?v=4)](https://github.com/noels "noels (1 commits)")[![ReadmeCritic](https://avatars.githubusercontent.com/u/15367484?v=4)](https://github.com/ReadmeCritic "ReadmeCritic (1 commits)")[![Spea](https://avatars.githubusercontent.com/u/495017?v=4)](https://github.com/Spea "Spea (1 commits)")[![alexandrfox](https://avatars.githubusercontent.com/u/199416?v=4)](https://github.com/alexandrfox "alexandrfox (1 commits)")

---

Tags

domfluentdomjquery-apiphpxmlxmlreaderxmlwriterxpathxmldomjqueryXMLReaderXMLWriterXpath

### Embed Badge

![Health badge](/badges/fluentdom-fluentdom/health.svg)

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

###  Alternatives

[sabre/xml

sabre/xml is an XML library that you may not hate.

52832.2M131](/packages/sabre-xml)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[veewee/xml

XML without worries

1835.9M29](/packages/veewee-xml)[querypath/querypath

HTML/XML querying and processing (like jQuery)

8197.0M27](/packages/querypath-querypath)[rct567/dom-query

DomQuery is a PHP library that allows easy 'jQuery like' DOM traversing and manipulation

134261.0k4](/packages/rct567-dom-query)[dkrnl/simplexmlreader

Wrapper XMLReader class, for simple SAX-reading(and simple XPath-queries) of huge(testing over 1G file) xml.

112951.5k](/packages/dkrnl-simplexmlreader)

PHPackages © 2026

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