Download the PHP package abgeo/xml-to-json without Composer
On this page you can find all versions of the php package abgeo/xml-to-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package xml-to-json
xml-to-json
Simple way to convert XML to JSON.
Installation
You can install this library with Composer:
composer require abgeo/xml-to-json
Usage
Include composer autoloader in your main file (Ex.: index.php)
require __DIR__.'/../vendor/autoload.php';
This package gives you the ability to convert XML string/file to JSON string/file.
For this, we have two converters:
ABGEO\XmlToJson\StringConverter
ABGEO\XmlToJson\FileConverter
Let's look at them in action.
Convert XML String to JSON string
Create simple XML file:
example.xml
Create an object of class ABGEO\XmlToJson\StringConverter
and read the content of example.xml
into a variable:
Now you can convert value of $xmlContent
variable to JSON object:
if you print this variable, you will get the following result:
Convert XML file to JSON file
Consider that you already have the example.xml
file described in the step above. Now let's create
an object of ABGEO\XmlToJson\FileConverter
class:
Using the convert
method of this object, you can simply convert the XML file to a JSON file:
Convert()
takes two arguments - the path to the input and output files.
If you do not specify an output file, by default it will be {$inputFile}.json.
Finally, the Convert ()
method will generate a new example.json
with the following content:
example.json
See full example here.
Changelog
Please see CHANGELOG for details.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Authors
- Temuri Takalandze - Initial work
License
Copyright © 2020 Temuri Takalandze.
Released under the MIT license.
All versions of xml-to-json with dependencies
ext-simplexml Version *
ext-json Version *