Skip to content

fracalo/arr2xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert php arrays to xml

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>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages