fracalo/arr2xml

A php class that converts multidimensional arrays to xml

Maintainers

Package info

github.com/fracalo/arr2xml

pkg:composer/fracalo/arr2xml

Statistics

Installs: 25

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2019-01-31 10:49 UTC

This package is auto-updated.

Last update: 2026-03-29 00:22:01 UTC


README

A php class that converts multidimensional arrays to xml.
It supports regular nodes, repeating node tags, attributes namespaces, cdata sections, and all you should need when building an xml data structure.

install

composer require fracalo/arr2xml

usage examples

use Fracalo\Arr2Xml\Arr2Xml;

$payload = [
    '_nodeName' => 'root',
    '_val' => [
        [
            '_nodeName' => 'items',
            '_val' => [
                [
                    '_nodeName' => 'item',
                    '_val' => 'Computer'
                ],
                [
                  '_nodeName' => 'item',
                  '_val' => 'Keyboard'
                ],
                [
                    '_nodeName' => 'item',
                    '_val' => 'Mouse'
                ],
                [
                    '_nodeName' => 'item',
                    '_val' => 'Monitor'
                ],
            ]
        ]
    ]
];

$x = new Arr2Xml('1.0', 'UTF-8');
$xml = $x->convert($payload);
output:
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <items>
    <item>Computer</item>
    <item>Keyboard</item>
    <item>Mouse</item>
    <item>Monitor</item>
  </items>
</root>