An open API service indexing awesome lists of open source software.

https://github.com/phpjunior/laravel-xml

This package is a simple XML to Array converter for Laravel.
https://github.com/phpjunior/laravel-xml

array laravel xml

Last synced: about 1 year ago
JSON representation

This package is a simple XML to Array converter for Laravel.

Awesome Lists containing this project

README

          

# Simple XML to Array Converter

[![Latest Version on Packagist](https://img.shields.io/packagist/v/php-junior/laravel-xml.svg?style=flat-square)](https://packagist.org/packages/php-junior/laravel-xml)
[![Total Downloads](https://img.shields.io/packagist/dt/php-junior/laravel-xml.svg?style=flat-square)](https://packagist.org/packages/php-junior/laravel-xml)

This package is a simple XML to Array converter for Laravel.

## Installation

You can install the package via composer:

```bash
composer require php-junior/laravel-xml
```

## Usage
default xml root tag is `root`
```php
use Illuminate\Support\Arr;

$data = [
'name' => 'John Doe',
'description' => 'This is a description',
'bio01' => 'This is a bio01',
'bio02' => 'This is a bio02',
'bio03' => 'This is a bio03',
'bio04' => 'This is a bio04',
];

$xml = Arr::toXml($data);

John Doe
...

// change root tag
$xml = Arr::toXml($data, 'user');

John Doe
...

// cdata tag
$xml = Arr::toXml($data, 'user', ['description']);

John Doe
description]]>
...

// cdata wildcard tag
$xml = Arr::toXml($data, 'user', ['bio*']);

John Doe
bio01]]>
bio02]]>
bio03]]>
bio04]]>

// multi-dimensional array
Arr::toXml([
'user' => [
[
'name' => 'User',
'email' => 'user@user.com'
],
[
'name' => 'User 2',
'email' => 'user2@user.com'
],
]
], 'users');


User
user@user.com


User 2
user2@user.com

// xml to array
$data = Arr::fromXml($xml);
[
'name' => 'John Doe',
'description' => 'This is a description',
'bio01' => 'This is a bio01',
'bio02' => 'This is a bio02',
'bio03' => 'This is a bio03',
'bio04' => 'This is a bio04',
]
```

### Testing

```bash
composer test
```

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

If you discover any security related issues, please email nyinyilwin1992@hotmail.com instead of using the issue tracker.

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.