2017 © Pedro PelĂĄez
 

library fluidxml

Concise and fluent XML manipulation library

image

servo/fluidxml

Concise and fluent XML manipulation library

  • Saturday, March 31, 2018
  • by daniele-orlando
  • Repository
  • 25 Watchers
  • 348 Stars
  • 80,575 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 30 Forks
  • 8 Open issues
  • 27 Versions
  • 17 % Grown

The README.md

Travis Build ![Coveralls Coverage][coveralls-coverage-badge] [Scrutinizer Quality][scrutinizer] Code Climate Quality, (*1)

Packagist License Packagist Last Release Packagist Total Downloads, (*2)

Changelog

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

PHP 8.1 is the new minimum required version., (*4)

..., (*5)

The full changes list., (*6)

br/, (*7)

Buy Me a Coffee at ko-fi.com , (*8)

FluidXML

Servo-PHP Logo        FluidXML Logo, (*9)

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

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

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

PHP Arrays are first class citizens., (*13)

$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;
<?xml version="1.0" encoding="UTF-8"?>
<doc>
  <title>The Theory Of Everything</title>
  <author>S. Hawking</author>
  <chapters>
    <chapter id="1">Ideas About The Universe</chapter>
    <chapter id="2">The Expanding Universe</chapter>
  </chapters>
</doc>

XPath is king., (*14)

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

And CSS Selectors rock., (*15)

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

// Many other selectors are available.

XML/CSS Namespaces are fully covered., (*16)

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

$book->add(<<<XML
    <cover class="front">
        <img src="http://goo.gl/kO3Iov"/>
    </cover>
    <cover class="back">
        <img src="http://goo.gl/kO3Iov"/>
    </cover>
XML
);

Everything is fluent, even iterations., (*18)

$book->query('//chapter')->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., (*19)

$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,br/ filtering is your friend., (*20)

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

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

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! » ^_^, (*22)

Many other 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() - ..., (*23)

Still doubts?

FluidXML is fun to use, concise and effective., (*24)

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

But you'll have the best answer trying it yourself., (*26)

100% Code Coverage, (*27)

Requirements

  • FluidXML v2 (latest) requires PHP >= 8.1
  • FluidXML v1 (legacy) requires PHP >=5.6 <8

Installation

  • Cloning the repository:
git clone https://github.com/servo-php/fluidxml.git
  • Using Composer:
composer require servo/fluidxml

Getting Started

  • Cloning the repository:
require_once 'FluidXml.php';
  • Using Composer:
require_once 'vendor/autoload.php';

use classes and functions as you need., (*28)

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

See the documentation to get started and become a ninja., (*29)

Documentation

_10 minutes reading_br/ Follow the Getting Started tutorial to become a ninja in no time., (*30)

Many other examples are available: - inside the doc/Examples/ folder - inside the specs/FluidXml.php file (as test cases), (*31)

All them cover from the simplest case to the most complex scenario., (*32)

Take a look at the APIs to discover all the available manipulation operations,br/ and go to the Wiki Page for more reading., (*33)

Donation

If you think this code is awesome or if you want to demonstratebr/ your immense gratitude ♄, buy me a coffe., (*34)

Buy Me a Coffee at ko-fi.com , (*35)

, (*36)

Roadmap

  • [ ] Extending the documentation
  • [ ] Expanding the APIs

Author

Daniele Orlando <fluidxml@danieleorlando.io>, (*37)

License

FluidXML is licensed under the BSD 2-Clause License., (*38)

See doc/LICENSE.txt for the details., (*39)

The Versions

31/03 2018

dev-master

9999999-dev https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

31/01 2017

1.21

1.21.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

12/07 2016

1.20.3

1.20.3.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

04/03 2016

1.20.2

1.20.2.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

21/02 2016

1.20.1

1.20.1.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

21/02 2016

1.20

1.20.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

24/01 2016

1.13

1.13.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

23/01 2016

1.12.4

1.12.4.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

18/01 2016

1.12.3

1.12.3.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

18/01 2016

1.12.2

1.12.2.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

16/01 2016

1.12.1

1.12.1.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

08/01 2016

1.12

1.12.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

07/01 2016

1.11

1.11.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

06/01 2016

1.10

1.10.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

03/01 2016

1.9

1.9.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

30/12 2015

1.8

1.8.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

29/12 2015

1.7

1.7.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

20/12 2015

1.6.2

1.6.2.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

20/12 2015

1.6.1

1.6.1.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

17/12 2015

1.6

1.6.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=5.6

 

The Development Requires

templating xml

11/12 2015

1.5

1.5.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

09/12 2015

1.4

1.4.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

02/12 2015

1.3

1.3.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

27/11 2015

1.2

1.2.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

25/11 2015

1.1.1

1.1.1.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

24/11 2015

1.1

1.1.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml

19/11 2015

1.0

1.0.0.0 https://github.com/servo-php/fluidxml

Concise and fluent XML manipulation library

  Sources   Download

BSD-2-Clause

The Requires

  • php >=7

 

The Development Requires

templating xml