Skip to content

evanwilliamsconsulting/fluidxml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FluidXML

Servo-PHP Logo

FluidXML is a PHP library, under the Servo PHP framework umbrella ☂,
designed to manipulate XML documents with a concise and fluent API.

It leverages XPath and the fluent programming pattern to be fun and effective.

STOP generating XML documents with template engines.
STOP using the boring and verbose DOMDocument.

FluidXML has been created to bring XML manipulation to the next level.

$book = new FluidXml();

$book->appendChild('title', 'The Theory Of Everything')
     ->appendChild('author', 'S. Hawking')
     ->appendChild('chapters', true)
         ->appendChild('chapter', 'Ideas About The Universe', ['id' => 1])
         ->appendChild('chapter', 'The Expanding Universe',   ['id' => 2])
     ->query('//chapter')
         ->setAttribute('lang', 'en');

Or, if you prefer, there is a concise syntax.

$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])
     ->query('//chapter')
         ->attr('lang', 'en');
echo $book->xml();
<?xml version="1.0" encoding="UTF-8"?>
<doc>
  <title>The Theory Of Everything</title>
  <author>S. Hawking</author>
  <chapters>
    <chapter id="1" lang="en">Ideas About The Universe</chapter>
    <chapter id="2" lang="en">The Expanding Universe</chapter>
  </chapters>
</doc>

Creating structured documents is so easy that you'll not believe.

$food = fluidxml();

// Batch insertion of nodes.
$food->add([ 'cake'  => 'Tiramisu',
             'pizza' => 'Margherita' ]);

// A bunch of egg's all with the same attribute.
$food->add([ ['egg'],
             ['egg'],
             ['egg'] ], ['price' => '0.25']);

// Deep tree structures are supported too.
$food->add([ 'fridge' => [ 'omelette' => 'with potato',
                           'soupe'    => 'with mashrooms' ],
             'freezer' => [ 'meat' => 'beef' ] ]);

XPath is king.

$book->query('//chapter')
     ->attr('status', 'read')
     ->query('..')
     ->attr('lang', 'en')
     ->query('../title')
     ->attr('country', 'us');

And sometimes string templates are the fastest way.

$book->appendChild('cover', true)
     ->appendXml(<<<XML
        <h1>The Theory Of Everything</h1>
        <img src="http://goo.gl/kO3Iov"/>
XML
);

XML Namespaces are fully covered too.

$book->namespace('xhtml', 'http://www.w3.org/1999/xhtml')
     ->namespace('svg',   'http://www.w3.org/2000/svg')
     ->appendChild('xhtml:h1')
     ->appendChild('svg:shape')
     ->query('//xhtml:h1');

Existing DOMDocument and SimpleXML documents are not a problem, just import them.

$fluidxml = fluidify($domdocument);

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

Still doubts?

Other three great reasons to use FluidXML, but you'll have the best answer trying it yourself.

FluidXML is fun to use, concise and effective.

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

100% Code Coverage

Requirements

  • PHP 5.6

Installation

  • Cloning the repository:

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


* **Using Composer**:
  ```sh
composer require servo/fluidxml

Getting Started

  • Cloning the repository:

require_once 'FluidXml.php';


* **Using Composer**:
  ```php
require_once 'vendor/autoload.php';

See the documentation to get started and become a ninja.

Documentation

10 minutes reading
Follow the Getting Started tutorial to become a ninja in no time.

Many other examples are available:

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

Take a look at the APIs to discover all the available manipulation operations,
and go to the Wiki Page for more reading.

Donation

If you think this project is awesome or if you want to demonstrate
your immense gratitude , donate 1cent.

Donate

Thank You! :D

Roadmap

  • [+] Porting the XML namespace implementation from the legacy FluidXML codebase
  • Expanding the APIs
  • [+] PHP 5.6 backport
  • Extending the documentation
Click here to lend your support to: FluidXML and make a donation at pledgie.com !

Author

Daniele Orlando <fluidxml@danieleorlando.com>

License

FluidXML is licensed under the BSD 2-Clause License.

See documents/License.txt for the details.

About

FluidXML, a PHP library for manipulating XML documents with a concise and fluent API.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 97.2%
  • Shell 2.7%
  • Vim Script 0.1%