{"id":22917435,"url":"https://github.com/mtownsend5512/collection-xml","last_synced_at":"2026-03-27T02:29:02.138Z","repository":{"id":33150706,"uuid":"153351895","full_name":"mtownsend5512/collection-xml","owner":"mtownsend5512","description":"The missing XML support for Laravel's Collection class.","archived":false,"fork":false,"pushed_at":"2025-02-21T15:04:51.000Z","size":24,"stargazers_count":43,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T08:08:01.568Z","etag":null,"topics":["api","array","collections","laravel","laravel-package","response-format","soap","toxml","xml"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-16T20:46:03.000Z","updated_at":"2025-02-21T15:04:30.000Z","dependencies_parsed_at":"2023-01-14T23:37:28.628Z","dependency_job_id":null,"html_url":"https://github.com/mtownsend5512/collection-xml","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fcollection-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fcollection-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fcollection-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fcollection-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/collection-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312078,"owners_count":20918344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","array","collections","laravel","laravel-package","response-format","soap","toxml","xml"],"created_at":"2024-12-14T06:17:55.958Z","updated_at":"2026-03-27T02:28:57.090Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"The missing XML support for Laravel's Collection class.\n\nThis package is designed to work with the [Laravel](https://laravel.com) framework.\n\n## Installation\n\nInstall via composer:\n\n```\ncomposer require mtownsend/collection-xml\n```\n\n### Registering the service provider\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\CollectionXml\\Providers\\CollectionXmlServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\CollectionXml\\Providers\\CollectionXmlServiceProvider::class);\n```\n\n## Quick start\n\n### Collection to xml\n\nConvert data inside a Laravel Collection into valid XML:\n\n```php\n$collection = collect([\n    'carrier' =\u003e 'fedex',\n    'id' =\u003e 123,\n    'tracking_number' =\u003e '9205590164917312751089',\n]);\n\n$xml = $collection-\u003etoXml();\n\n// Returns\n\u003c?xml version=\"1.0\"?\u003e\n\u003croot\u003e\n    \u003ccarrier\u003efedex\u003c/carrier\u003e\n    \u003cid\u003e123\u003c/id\u003e\n    \u003ctracking_number\u003e9205590164917312751089\u003c/tracking_number\u003e\n\u003c/root\u003e\n```\n\n### Collection to soap xml\n\n*Heads up, this method is the most temperamental part of this package. Please thoroughly check your SOAP endpoint and requirements for best usage.*\n\n```php\n$collection = collect([\n    'carrier' =\u003e 'fedex',\n    'id' =\u003e 123,\n    'tracking_number' =\u003e '9205590164917312751089',\n]);\n\n$xml = $collection-\u003etoSoapXml('request', 'xmlBody', 'https://yourwebserver/service.asmx?wsdl');\n\n// Returns\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cSOAP-ENV:Envelope\n    xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n    xmlns:ns1=\"https://yourwebserver/service.asmx?wsdl\"\u003e\n    \u003cSOAP-ENV:Body\u003e\n        \u003cns1:ProcessXMLRequest\u003e\n            \u003cns1:xmlBody\u003e\n                \u003c?xml version=\"1.0\"?\u003e\n                \u003crequest\u003e\n                    \u003ccarrier\u003efedex\u003c/carrier\u003e\n                    \u003cid\u003e123\u003c/id\u003e\n                    \u003ctracking_number\u003e9205590164917312751089\u003c/tracking_number\u003e\n                \u003c/request\u003e\n            \u003c/ns1:xmlBody\u003e\n        \u003c/ns1:ProcessXMLRequest\u003e\n    \u003c/SOAP-ENV:Body\u003e\n\u003c/SOAP-ENV:Envelope\u003e\n```\n\n**Please note:** the SoapFactory class will ping the ``$fullUrl`` to see if it is valid as it builds the SOAP xml. It will not trigger an api interaction, but you will experience an exception if your url is invalid.\n\n### Array to xml\n\nConvert an array into xml without using a collection:\n\n```php\n$array = [\n    'carrier' =\u003e 'fedex',\n    'id' =\u003e 123,\n    'tracking_number' =\u003e '9205590164917312751089',\n];\n\n$xml = array_to_xml($array);\n```\n\n## Helpers, methods, and arguments\n\n**Helper**\n\n``array_to_xml($array, $root = '')``\n\nThe ``$root`` argument allows you to customize the root xml element. Default is ``\u003croot\u003e``.\n\n**Collection method**\n\n``-\u003etoXml($root)``\n\nSee ``array_to_xml()`` above.\n\n**Collection method**\n\n``-\u003etoSoapXml($root = '', $soapRoot = '', $fullUrl, array $options = [])``\n\nThe ``$root`` argument allows you to customize the inner root xml element. Default is ``\u003croot\u003e``.\n\n``$soapRoot`` is the outer xml root element. Default is ``xmlBody``.\n\n``$fullUrl`` will be the fully qualified SOAP endpoint e.g. https://yourwebserver/service.asmx?wsdl. **Please note:** the SoapFactory class will ping the ``$fullUrl`` to see if it is valid as it builds the SOAP xml. It will not trigger an api interaction, but you will experience an exception if your url is invalid.\n\n``$options`` will be an array of valid options for PHP's [SoapClient](http://php.net/manual/en/class.soapclient.php) class. By default ``['trace' =\u003e 1]`` is set.\n\n## Purpose\n\nLaravel has always favored json over xml with its api structure. Inevitably, developers will be required to interact with files or apis that require xml, and they are often left to figure it out for themselves.\n\nThis package aims to bring painless xml support to Laravel's Collection class, and bring a few useful helpers along.\n\n## Other packages you may be interested in\n\n- [mtownsend/request-xml](https://github.com/mtownsend5512/request-xml)\n- [mtownsend/response-xml](https://github.com/mtownsend5512/response-xml)\n- [mtownsend/xml-to-array](https://github.com/mtownsend5512/xml-to-array)\n\n## Credits\n\n- Mark Townsend\n- [Spatie](https://spatie.be/)\n- [All Contributors](../../contributors)\n\n## Testing\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fcollection-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Fcollection-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fcollection-xml/lists"}