PHP code example of rufov / converter-array-xml

1. Go to this page and download the library: Download rufov/converter-array-xml library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rufov / converter-array-xml example snippets


use RufovS\ConverterArrayXML\ConverterArrayXML;

$xml = <<<_XML
<?xml version="1.0"

$result = [
    'root' => [
        '_attributes' => [
                'xmlns:xs=' => 'http://www.w3.org/2001/XMLSchema',
                'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
        ],
        'GoodGuy' => [
             '_attributes' => [
                'attr1' => 'value'
            ],
            'name' => [
                '_cdata' => '<h1>Luke Skywalker</h1>'
            ],
            'weapon' => 'Lightsaber'
        ],
        'BadGuy' => [
            'name' => 'Sauron',
            'weapon' => 'Evil Eye'
        ]
    ]
];

use RufovS\ConverterArrayXML\ConverterArrayXML;

$array = [
    'root' => [
        '_attributes' => [
                'xmlns:xs=' => 'http://www.w3.org/2001/XMLSchema',
                'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
        ],
        'GoodGuy' => [
             '_attributes' => [
                'attr1' => 'value'
            ],
            'name' => [
                '_cdata' => '<h1>Luke Skywalker</h1>'
            ],
            'weapon' => 'Lightsaber'
        ],
        'BadGuy' => [
            'name' => 'Sauron',
            'weapon' => 'Evil Eye'
        ]
    ]
];

$result = ConverterArrayXML::arrayToXml($array);