alextartan / xml2array
Lightweight xml<->array conversion.
Installs: 35 608
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 6
Requires
- php: >=7.4
- ext-dom: *
- ext-libxml: *
Requires (Dev)
- infection/infection: ^0.13.0 || ^0.15.0 || ^0.16.0 || ^0.20.0
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: 0.11.20
- phpstan/phpstan-phpunit: ^0.11
- phpstan/phpstan-strict-rules: ^0.11
- phpunit/phpunit: ^8.2.0 || ^9.0.0
- squizlabs/php_codesniffer: ^3.4
- dev-master
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 0.5.0
- 0.2.0
- 0.1.0
- 0.0.1
- dev-dependabot/composer/phpunit/phpunit-9.5.28
- dev-dependabot/composer/php-coveralls/php-coveralls-2.5.3
- dev-dependabot/composer/guzzlehttp/guzzle-7.4.5
- dev-dependabot/composer/squizlabs/php_codesniffer-3.7.1
- dev-dependabot/composer/guzzlehttp/psr7-1.8.5
- dev-dependabot/composer/infection/infection-0.21.5
This package is auto-updated.
Last update: 2024-12-21 20:46:50 UTC
README
Array <-> XML conversion package
Lightweight XML parser
Current build status
Install
The easiest way is to use composer
:
composer require alextartan/xml2array
Notes:
Latest release requires PHP
>= 7.2 and the dom
extension (ext-dom
)
For PHP
<= 7.2, use version 1.0.2
Usage
ArrayToXml
Convert an XML (either DOMDocument or string) to an array
// default value:
$config = [
'version' => '1.0',
'encoding' => 'UTF-8',
'attributesKey' => '@attributes',
'cdataKey' => '@cdata',
'valueKey' => '@value',
'useNamespaces' => false,
'forceOneElementArray => false,
];
$xtoa = new XmlToArray($config);
$array = $xtoa->buildArrayFromString($xmlString);
$array = $xtoa->buildArrayFromDomDocument($xmlDom);
XmlToArray
Convert an array to a DOMDocument
// default value:
$config = [
'version' => '1.0',
'encoding' => 'UTF-8',
'attributesKey' => '@attributes',
'cdataKey' => '@cdata',
'valueKey' => '@value',
'formatOutput' => false,
];
$atox = new ArrayToXml($config);
$xml = $atox->buildXml($array);
Issues and pull requests.
Any issues found should be reported in this repository issue tracker, issues will be fixed when possible. Pull requests will be accepted, but please adhere to the PSR2 coding standard. All builds must pass in order to merge the PR.