PHP code example of ordinary9843 / xml-master

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

    

ordinary9843 / xml-master example snippets



Ordinary9843\XmlMaster;

$xmlMaster = new XmlMaster();

// Set XML version.
$xmlMaster->setVersion('1.0');

// Set XML encoding type.
$xmlMaster->setEncoding('UTF-8');

/**
 * Array conversion to XML.
 *
 * Output:
 *
 * <root>
 *   <user>
 *     <name>Software Engineer</name>
 *     <email>[email protected]</email>
 *     <title>Sortware Engineer</title>
 *     <website>https://github.com/ordinary9843</website>
 *   </user>
 * </root>
 */
$xmlMaster->convert([
    'user' => [
        'name' => 'Software Engineer',
        'email' => '[email protected]',
        'title' => 'Sortware Engineer',
        'website' => 'https://github.com/ordinary9843'
    ]
]);

/**
 * Convert array to XML and save the result.
 */
$xmlMaster->save('./test.xml', [
    'user' => [
        'name' => 'Software Engineer',
        'email' => '[email protected]',
        'title' => 'Sortware Engineer',
        'website' => 'https://github.com/ordinary9843'
    ]
]);

/**
 * Get all messages.
 *
 * Output: [
 *  '[INFO] Message.',
 *  '[ERROR] Message.'
 * ]
 */
$xmlMaster->getMessages();