laravie/parser

XML Document Parser for PHP

Maintainers

Details

github.com/laravie/parser

Source

Fund package maintenance!
crynobone
Liberapay

Installs: 1 657 649

Dependents: 9

Suggesters: 1

Security: 0

Stars: 229

Watchers: 7

Forks: 24

v2.4.0 2024-03-26 14:57 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

<?php

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

by just writing this:

<?php

use Laravie\Parser\Xml\Reader;
use Laravie\Parser\Xml\Document;

$xml = (new Reader(new Document()))->load('path/to/above.xml');

$user = $xml->parse([
    'id' => ['uses' => 'user.id'],
    'email' => ['uses' => 'user.email'],
    'followers' => ['uses' => 'user::followers'],
]);

Installation

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

{
    "require": {
        "laravie/parser": "^2.0"
    }
}

And then run composer install from the terminal.

Quick Installation

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

composer require "laravie/parser=^2.0"