Giter Site home page Giter Site logo

fluidxml's Introduction

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 <[email protected]>

License

FluidXML is licensed under the BSD 2-Clause License.

See documents/License.txt for the details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.