Download the PHP package noki/xml-converter without Composer
On this page you can find all versions of the php package noki/xml-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download noki/xml-converter
More information about noki/xml-converter
Files in noki/xml-converter
Package xml-converter
Short Description Laravel XML Converter is Laravel package for converting XML to JSON and XML to array.
License MIT
Homepage https://github.com/novakurosevic/xml-converter
Informations about the package xml-converter
Laravel XML Converter Package
๐งพ Introduction
Since I started working with Laravel, I always wanted a simple helper that could convert XML files to JSON.
I created the first version of this package to do exactly that. While the package isn't perfect, it can handle a wide range of XML inputs. If you find any issues, feel free to report them.
I should note that this package was created with the help of AI. In my case, I used ChatGPT, and it saved me many hours of coding.
โ What does this package do?
This package provides a flexible and powerful way to convert XML strings to JSON or PHP arrays. It supports:
- DTD and XSD validation
- Namespace tagging
- CDATA handling
๐ Installation
Requirements
- PHP >= 8.1
- Laravel >= 9
- PHP Extensions:
simplexml
libxml
dom
Composer Installation
โ๏ธ PHP Extensions Setup
Linux (Debian/Ubuntu)
Example for PHP 8.3 โ be sure to use the correct package names:
First, check your PHP version:
Then install extensions for your version:
macOS (with Homebrew)
Required extensions (
simplexml
,libxml
,dom
) are bundled with PHP on macOS.
Windows
- Open your
php.ini
file. -
Ensure the following lines are uncommented (remove the
;
at the beginning): - Restart your web server (Apache, Nginx) or PHP-FPM.
๐ฆ Usage
Namespace
1. Convert XML to JSON
2. Convert XML to array
3. Full control with options
namespace_in_tag_name
: If true, keys will include namespace prefixes (e.g.,ns:tag
).is_cdata
: If true, CDATA sections are preserved as-is.schema_path
:- Path to an
.xsd
file for XSD validation. - Use
''
(empty string) to enable DTD validation (your XML must contain<!DOCTYPE ...>
). - Use
null
to skip validation.
- Path to an
4. Convert XML to JSON with options
๐งช Example
Sample XML with namespaces and CDATA
๐ Error Handling
- If the XML is invalid, an
InvalidArgumentException
will be thrown. - If schema validation fails, a descriptive exception is thrown (with optional logging).
- CDATA sections and empty tags are handled gracefully.
๐งฉ Integration with Laravel
You can use this package in controllers, services, or jobs:
๐ License
MIT License. See LICENSE.md for details.
๐ Contributing
Feel free to fork and submit a PR! Bug reports and feature requests are always welcome.
๐ Author
๐ Changelog
Please see CHANGELOG.md for recent updates.
All versions of xml-converter with dependencies
ext-simplexml Version *
ext-libxml Version *
ext-dom Version *