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.
- Host: GitHub
- URL: https://github.com/phpjunior/laravel-xml
- Owner: PHPJunior
- License: mit
- Created: 2024-10-15T12:05:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-10T15:13:32.000Z (over 1 year ago)
- Last Synced: 2025-04-05T20:58:56.222Z (about 1 year ago)
- Topics: array, laravel, xml
- Language: PHP
- Homepage:
- Size: 61.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Simple XML to Array Converter
[](https://packagist.org/packages/php-junior/laravel-xml)
[](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.