orchestra/parser

XML Document Parser for Laravel and PHP

Installs: 12 683

Dependents: 0

Stars: 52

Watchers: 2

Forks: 7

Open Issues: 2

v3.2.1 2015-12-18 07:48 UTC

README

Join the chat at https://gitter.im/orchestral/platform/components

Parser Component is a framework agnostic package that provide a simple way to parse XML to array without having to write a complex logic.

Latest Stable Version Total Downloads MIT License Build Status Coverage Status Scrutinizer Quality Score

Imagine if you can parse

<api>
    <user followers="5">
        <id>1</id>
        <email>crynobone@gmail.com</email>
    </user>
</api>

to

$user = [
    'id' => '1',
    'email' => 'crynobone@gmail.com',
    'followers' => '5'
];

by just writing this:

$xml = XmlParser::load('path/to/above.xml');
$user = $xml->parse([
    'id' => ['uses' => 'user.id'],
    'email' => ['uses' => 'user.email'],
    'followers' => ['uses' => 'user::followers'],
]);

Table of Content

Version Compatibility

Laravel Parser
4.1.x 2.1.x
4.2.x 2.2.x
5.0.x 3.0.x
5.1.x 3.1.x
5.2.x 3.2.x
5.3.x 3.3.x@dev

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require": {
        "orchestra/parser": "~3.0"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplify by using the following command:

composer require "orchestra/parser=~3.0"

Configuration

Next add the service provider in config/app.php.

'providers' => [

    // ...

    Orchestra\Parser\XmlServiceProvider::class,
],

Aliases

You might want to add Orchestra\Parser\Xml\Facade to class aliases in config/app.php:

'aliases' => [

    // ...

    'XmlParser' => Orchestra\Parser\Xml\Facade::class,
],