All Projects → servo-php → Fluidxml

servo-php / Fluidxml

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

Labels

Projects that are alternatives of or similar to Fluidxml

Stroom
Stroom is a highly scalable data storage, processing and analysis platform.
Stars: ✭ 344 (-17.51%)
Mutual labels:  xml
Neogfx
Cross-platform GPU-oriented C++ application/game framework
Stars: ✭ 362 (-13.19%)
Mutual labels:  xml
Stream Parser
⚡ PHP7 / Laravel Multi-format Streaming Parser
Stars: ✭ 391 (-6.24%)
Mutual labels:  xml
Thymeleaf Spring
Thymeleaf integration module for Spring
Stars: ✭ 349 (-16.31%)
Mutual labels:  xml
Java nfe
Projeto Open Source Java - NFe, NFce
Stars: ✭ 360 (-13.67%)
Mutual labels:  xml
Tikxml
Modern XML Parser for Android
Stars: ✭ 370 (-11.27%)
Mutual labels:  xml
Getsimplecms
GetSimple CMS
Stars: ✭ 333 (-20.14%)
Mutual labels:  xml
Better Xlsx
A better xlsx library.
Stars: ✭ 395 (-5.28%)
Mutual labels:  xml
Tbox
🎁 A glib-like multi-platform c library
Stars: ✭ 3,800 (+811.27%)
Mutual labels:  xml
Xpath
XPath package for Golang, supports HTML, XML, JSON document query.
Stars: ✭ 376 (-9.83%)
Mutual labels:  xml
Hashover Next
This branch will be HashOver 2.0
Stars: ✭ 353 (-15.35%)
Mutual labels:  xml
Recog
Pattern recognition for hosts, services, and content
Stars: ✭ 360 (-13.67%)
Mutual labels:  xml
Meza
A Python toolkit for processing tabular data
Stars: ✭ 374 (-10.31%)
Mutual labels:  xml
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (-16.55%)
Mutual labels:  xml
Dog Ceo Api
The API hosted at dog.ceo
Stars: ✭ 393 (-5.76%)
Mutual labels:  xml
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-19.66%)
Mutual labels:  xml
Node Rest Client
REST API client from node.js
Stars: ✭ 365 (-12.47%)
Mutual labels:  xml
Wikiteam
Tools for downloading and preserving wikis. We archive wikis, from Wikipedia to tiniest wikis. As of 2020, WikiTeam has preserved more than 250,000 wikis.
Stars: ✭ 404 (-3.12%)
Mutual labels:  xml
Nextjs Sitemap Generator
Generate sitemap.xml from nextjs pages
Stars: ✭ 395 (-5.28%)
Mutual labels:  xml
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (-10.79%)
Mutual labels:  xml

Travis Build Coveralls Coverage Scrutinizer Quality Code Climate Quality

Packagist License Packagist Last Release Packagist Total Downloads

Changelog

1.20.3 (2016-07-12): fixes wrong handling of null/empty node value.

...

The full changes list.


Buy Me a Coffee at ko-fi.com

FluidXML

Servo-PHP Logo        FluidXML Logo

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;
<?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.

$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(<<<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.

$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');
        });

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 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?

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

Requirements

  • PHP 5.6

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.

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.

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 code is awesome or if you want to demonstrate
your immense gratitude , buy me a coffe.

Buy Me a Coffee at ko-fi.com

Roadmap

  • [x] PHP 5.6 backport
  • [ ] Extending the documentation
  • [ ] Expanding the APIs

Author

Daniele Orlando <[email protected]>

License

FluidXML is licensed under the BSD 2-Clause License.

See documents/License.txt for the details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].