PHP code example of bupy7 / xml-constructor

1. Go to this page and download the library: Download bupy7/xml-constructor 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/ */

    

bupy7 / xml-constructor example snippets


$xml = new XmlConstructor();
$in = [
    [
        'tag' => 'root',
        'elements' => [
            [
                'tag' => 'tag1',
                'attributes' => [
                    'attr1' => 'val1',
                    'attr2' => 'val2',
                ],
            ],
            [
                'tag' => 'tag2',
                'content' => 'content2',
            ],
            [
                'tag' => 'tag3',
                'elements' => [
                    [
                        'tag' => 'tag4',
                        'content' => 'content4',
                    ],
                ],
            ],
            [
                'tag' => 'tag4',
                'content' => '<b>content4</b>',
                'cdata' => true, // by default - false, see https://en.wikipedia.org/wiki/CDATA
            ],
        ],
    ],
];
echo $xml->fromArray($in)->toOutput();

$xml = new XmlConstructor([
    // Indent each line in the XML document. 4 space by default.
    'indentString' => '    ',
    /* Header document tag. "<?xml version="1.0" encoding="UTF-8"

~/.composer/vendor/bin/php-cs-fixer fix --config=./phpcs.php --verbose

composer global