A PHP XML parser and compiler that provides an easy way to convert XML into native PHP arrays and back again. No dependencies on external libraries or extensions.

v2.0.0 2020-02-22 13:28 UTC

This package is auto-updated.

Last update: 2020-10-22 15:22:46 UTC


SensioLabsInsight Code Climate Test Coverage Latest Stable Version Build Status

A PHP XML parser class that provides an easy way to convert XML into native PHP arrays and back again. It has no dependencies on any external libraries or extensions bundled with PHP. The entire parser is concisely written in PHP.

This project is actively maintained. It is used in our production code. If you spot an issue, please let us know through the Issues section on our Github project page:

In short, this project makes sense for those who want to simplify their PHP install and use, have a need for a simple XML parser, but don't much care about speed.


PHP 7.2+



Simply add a dependency on greencape/xml-converter to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a dependency on XML Converter:

    "require": {
        "greencape/xml-converter": "*@dev"

For a system-wide installation via Composer, you can run:

$ composer global require 'greencape/xml-converter=*'

Make sure you have ~/.composer/vendor/bin/ in your path.

Usage Examples

XML String to PHP Array


$xml = new \GreenCape\Xml\Converter('<?xml version="1.0" encoding="ISO-8859-1"?>

XML File to PHP Array

$xml = new \GreenCape\Xml\Converter('some_xml_file.xml');

PHP Array to XML String

$xml = new \GreenCape\Xml\Converter(array(
    'breakfast_menu' => array(
            'food' => array(
                'name' => 'Waffles'
echo $xml;