orchestra/parser

XML Document Parser for Laravel and PHP

Maintainers

Details

github.com/orchestral/parser

Source

Fund package maintenance!
Liberapay
paypal.me/crynobone

Installs: 1 444 086

Dependents: 4

Suggesters: 0

Security: 0

Stars: 445

Watchers: 19

Forks: 48

v9.0.0 2024-03-26 15:24 UTC

README

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

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

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:

use Orchestra\Parser\Xml\Facade as XmlParser;

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

Version Compatibility

Installation

To install through composer, run the following command from terminal:

composer require "orchestra/parser"

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,
],