PHPackages                             servo/fluidxml - 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. [Templating &amp; Views](/categories/templating)
4. /
5. servo/fluidxml

ActiveLibrary[Templating &amp; Views](/categories/templating)

servo/fluidxml
==============

Concise and fluent XML manipulation library

2.0.0(2y ago)4641.2M—6%44[2 PRs](https://github.com/downforcetech/fluidxml.php/pulls)8BSD-2-ClausePHPPHP ^8.1

Since Nov 19Pushed 1y ago24 watchersCompare

[ Source](https://github.com/downforcetech/fluidxml.php)[ Packagist](https://packagist.org/packages/servo/fluidxml)[ Docs](https://github.com/servo-php/fluidxml)[ RSS](/packages/servo-fluidxml/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (28)Used By (8)

[![Travis Build](https://camo.githubusercontent.com/5ea51480e9d68e32992e7e87dc871ea873bd678545baf369b7e76707c61faec2/68747470733a2f2f7472617669732d63692e6f72672f736572766f2d7068702f666c756964786d6c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/servo-php/fluidxml)[![Coveralls Coverage](https://camo.githubusercontent.com/a9ebc5c4bb5e8e23f2d71a79ce2e869d95892587e0ec1680b791405194eca839/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736572766f2d7068702f666c756964786d6c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/servo-php/fluidxml?branch=master)[![Scrutinizer Quality](https://camo.githubusercontent.com/b03d84a124447842670ce97be823c4f854802c4c9e031da35189f58a85061073/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736572766f2d7068702f666c756964786d6c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/servo-php/fluidxml/?branch=master)[![Code Climate Quality](https://camo.githubusercontent.com/4d65f9452a461b931941039e8727f880630a59926ac037956354d3c89e4d4e98/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f736572766f2d7068702f666c756964786d6c2f6261646765732f6770612e737667)](https://codeclimate.com/github/servo-php/fluidxml)

[![Packagist License](https://camo.githubusercontent.com/db07747820642bc3e79a31cb937ec736d2340a76d4e3d0a869e480a3bb84131d/68747470733a2f2f706f7365722e707567782e6f72672f736572766f2f666c756964786d6c2f6c6963656e7365)](https://packagist.org/packages/servo/fluidxml)[![Packagist Last Release](https://camo.githubusercontent.com/bd605491368d6dc42488123859443266f25020469ab732f0546aacda06f807fa/68747470733a2f2f706f7365722e707567782e6f72672f736572766f2f666c756964786d6c2f762f737461626c65)](https://packagist.org/packages/servo/fluidxml)[![Packagist Total Downloads](https://camo.githubusercontent.com/56c0546cf9f9f6e40dca09ab8da0519e4b6794aa32cccf53a326a1943eccbce6/68747470733a2f2f706f7365722e707567782e6f72672f736572766f2f666c756964786d6c2f646f776e6c6f616473)](https://packagist.org/packages/servo/fluidxml)

Changelog
---------

[](#changelog)

**2.0.0** (2023-11-06):

*PHP 8.1 is the new minimum required version.*

**...**

[The full changes list.](https://github.com/servo-php/fluidxml/blob/master/CHANGELOG.txt)

[ ![Buy Me a Coffee at ko-fi.com](https://camo.githubusercontent.com/bd3c39f28b205bd84e8847528e7a21ba063707c867961b59ec9bc70c25c14bff/68747470733a2f2f617a3734333730322e766f2e6d7365636e642e6e65742f63646e2f6b6f6669352e706e673f763d61)](https://ko-fi.com/2216WXOPLSZER)FluidXML
========

[](#fluidxml)

[![Servo-PHP Logo](https://camo.githubusercontent.com/7f9eee3e497a4b538d458de9a6ae5e2ce1531e5fa5cdf86075843b121ec23f3b/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f536572766f5f6c6f676f2e706e67)](https://camo.githubusercontent.com/7f9eee3e497a4b538d458de9a6ae5e2ce1531e5fa5cdf86075843b121ec23f3b/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f536572766f5f6c6f676f2e706e67)

 [![FluidXML Logo](https://camo.githubusercontent.com/e5a4253b6581fea5a87c40068b757f36f225d174adc85958ec7ccf423deeba3e/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f466c756964786d6c5f6c6f676f2e706e67)](https://camo.githubusercontent.com/e5a4253b6581fea5a87c40068b757f36f225d174adc85958ec7ccf423deeba3e/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f466c756964786d6c5f6c6f676f2e706e67)

FluidXML is a PHP library designed to manipulate XML documents with a **concise** and **fluent** API.
It leverages the fluent programming pattern to be **fun and effective**.

```
$book = fluidxml();

$book->add('title', 'The Theory Of Everything')
     ->add('author', 'S. Hawking')
     ->add('chapters', true)
         ->add('chapter', 'Ideas About The Universe', ['id' => 1])
         ->add('chapter', 'The Expanding Universe',   ['id' => 2]);
```

Or, if you prefer, there is an **extended syntax**.

```
$book = new FluidXml();

$book->addChild('title', 'The Theory Of Everything')
     ->addChild('author', 'S. Hawking')
     ->addChild('chapters', true)
         ->addChild('chapter', 'Ideas About The Universe', ['id' => 1])
         ->addChild('chapter', 'The Expanding Universe',   ['id' => 2]);
```

With FluidXML the DOM manipulation becomes **fast**, **clear** and **expressive**.

**PHP Arrays** are first class citizens.

```
$book->add([ 'title'  => 'The Theory Of Everything',
             'author' => 'S. Hawking',
             'chapters' => [
                    [ 'chapter' => [
                            '@id' => '1',
                            '@'   => 'Ideas About The Universe' ] ],
                    [ 'chapter' => [
                            '@id' => '2',
                            '@'   => 'The Expanding Universe' ] ],
           ]]);
```

```
echo $book;
```

```

  The Theory Of Everything
  S. Hawking

    Ideas About The Universe
    The Expanding Universe

```

**XPath** is king.

```
$book->query('//title', '//author', '//chapter')
        ->attr('lang', 'en');
```

And **CSS Selectors** rock.

```
$book->query('#id', '.class1.class2', 'div p > span')
        ->attr('lang', 'en');

// Many other selectors are available.
```

**XML/CSS Namespaces** are fully covered.

```
$book->namespace('xhtml', 'http://www.w3.org/1999/xhtml')
     ->add('xhtml:h1')
     ->query('//xhtml:h1')  // XPath namespace.
     ->query('xhtml|h1');   // CSS namespace.
```

And sometimes **XML Fragments** are the fastest way.

```
$book->add(each(function ($i) {
    $this->attr('id', $i);
});
```

```
$book->query('//chapters')
        ->times(3)
            ->add('chapter')
        ->times(4, function ($i) {
            $this->add('chapter');
            $this->add('illustration');
        });
```

You can **map** nodes easily too.

```
$chaptersIds = $book->query('//chapter')->map(function ($i, $it) {
    return $it->getAttribute('id');
});
```

```
$book->query('//chapters')
        ->times(3)
            ->add('chapter')
        ->times(4, function ($i) {
            $this->add('chapter');
            $this->add('illustration');
        });
```

Whether some queries are too complex to express with XPath/CSS,
**filtering** is your friend.

```
$book->query('//chapters')
        ->filter(function ($i, $node) {
            return $i % 2 === 0;
        })
        ->attr('even');
```

Interoperability with existing **DOMDocument** and **SimpleXML** is simply magic.
Import them or inject them in any point of the FluidXML flow just like that.

```
fluidxml($domdocument)
    ->query('/html/body')
         ->add($simplexml);

// Yes, we merged a DOMDocument with a SimpleXMLElement
// and everything is still fluid.
```

Don't be shy and tell it: **« IT'S AWESOME! »** ^\_^

Many other [APIs](https://github.com/servo-php/fluidxml/wiki/APIs) are available:

- `__invoke()`
- `append()`/`appendSibling()`
- `prepend()`/`prependSibling()`
- `addText()`
- `text()`/`setText()`
- `addCdata()`
- `cdata()`/`setCdata()`
- `addComment()`
- `comment()`/`setComment()`
- `remove()`
- `size()`/`length()`
- `load()`
- `save()`
- `dom()`
- `xml()`
- `html()`
- `__toString()`
- `array()`
- ...

Still doubts?
-------------

[](#still-doubts)

FluidXML is **fun** to use, **concise** and **effective**.

If it's not enough, it has a comprehensive test suite with a **100% code coverage**.

But you'll have the best answer trying it yourself.

[![100% Code Coverage](https://camo.githubusercontent.com/6bbfba9061bf1773e0d383051b631763b3d8392a3080d50ee2a2cf7b5eb8d295/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f466c756964584d4c5f636f64655f636f7665726167652e706e67)](https://camo.githubusercontent.com/6bbfba9061bf1773e0d383051b631763b3d8392a3080d50ee2a2cf7b5eb8d295/68747470733a2f2f627974656275636b65742e6f72672f64616e69656c655f6f726c616e646f2f626974686f7374696e672f7261772f6d61737465722f466c756964584d4c5f636f64655f636f7665726167652e706e67)

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

[](#requirements)

- **FluidXML v2** (latest) requires **PHP &gt;= 8.1**
- FluidXML v1 (legacy) requires **PHP &gt;=5.6 &lt;8**

Installation
------------

[](#installation)

- **Cloning the repository**:

```
git clone https://github.com/servo-php/fluidxml.git
```

- **Using Composer**:

```
composer require servo/fluidxml
```

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

[](#getting-started)

- **Cloning the repository**:

```
require_once 'FluidXml.php';
```

- **Using Composer**:

```
require_once 'vendor/autoload.php';
```

`use` classes and functions as you need.

```
use function \FluidXml\fluidxml;
use function \FluidXml\fluidns;
use function \FluidXml\fluidify;
```

```
use \FluidXml\FluidXml;
use \FluidXml\FluidNamespace;
```

See the [documentation](#documentation) to get started and become a [ninja](http://1.viki.io/d/1863c/8b75dc48c9.gif).

Documentation
-------------

[](#documentation)

*10 minutes reading*
Follow the [Getting Started tutorial](https://github.com/servo-php/fluidxml/wiki/Getting-Started) to become a [ninja](http://1.viki.io/d/1863c/8b75dc48c9.gif) in no time.

Many other examples are available:

- inside the [`doc/Examples/`](https://github.com/servo-php/fluidxml/blob/master/doc/Examples/) folder
- inside the [`specs/FluidXml.php`](https://github.com/servo-php/fluidxml/blob/master/specs/FluidXml.php) file (as test cases)

All them cover from the simplest case to the most complex scenario.

Take a look at the [APIs](https://github.com/servo-php/fluidxml/wiki/APIs) to discover all the available manipulation operations,
and go to the [Wiki Page](https://github.com/servo-php/fluidxml/wiki) for more reading.

Donation
--------

[](#donation)

If you think this code is **awesome** or if you want to demonstrate
your immense gratitude **[♥](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Heart_coraz%C3%B3n.svg/2000px-Heart_coraz%C3%B3n.svg.png)**, *buy me a coffe*.

[ ![Buy Me a Coffee at ko-fi.com](https://camo.githubusercontent.com/bd3c39f28b205bd84e8847528e7a21ba063707c867961b59ec9bc70c25c14bff/68747470733a2f2f617a3734333730322e766f2e6d7365636e642e6e65742f63646e2f6b6f6669352e706e673f763d61)](https://ko-fi.com/2216WXOPLSZER)Roadmap
-------

[](#roadmap)

- Extending the documentation
- Expanding the APIs

Author
------

[](#author)

Daniele Orlando [&lt;fluidxml@danieleorlando.io&gt;](mailto:fluidxml@danieleorlando.io)

License
-------

[](#license)

FluidXML is licensed under the [BSD 2-Clause License](https://opensource.org/licenses/BSD-2-Clause).

See [`doc/LICENSE.txt`](https://github.com/servo-php/fluidxml/blob/master/LICENSE.txt) for the details.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity60

Solid adoption and visibility

Community29

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.2% 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 ~112 days

Recently: every ~704 days

Total

27

Last Release

922d ago

Major Versions

1.21 → 2.0.02023-11-08

PHP version history (3 changes)1.0PHP &gt;=7

1.6PHP &gt;=5.6

2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6e0bfc47647a2f5918be05a32663ec08ff50bdda78807978696030851bfc9e1?d=identicon)[daniele-orlando](/maintainers/daniele-orlando)

---

Top Contributors

[![daniele-orlando](https://avatars.githubusercontent.com/u/504386?v=4)](https://github.com/daniele-orlando "daniele-orlando (139 commits)")[![nicekiwi](https://avatars.githubusercontent.com/u/738975?v=4)](https://github.com/nicekiwi "nicekiwi (4 commits)")[![alepeino](https://avatars.githubusercontent.com/u/5054081?v=4)](https://github.com/alepeino "alepeino (3 commits)")

---

Tags

phpxmlxmltemplating

###  Code Quality

Static AnalysisRector

### Embed Badge

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

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

###  Alternatives

[twig/twig

Twig, the flexible, fast, and secure template language for PHP

8.4k443.2M5.8k](/packages/twig-twig)[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[smarty/smarty

Smarty - the compiling PHP template engine

2.3k39.1M395](/packages/smarty-smarty)[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)[jasny/twig-extensions

A set of useful Twig filters

10710.2M8](/packages/jasny-twig-extensions)

PHPackages © 2026

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