PHP code example of horat1us / php-xml-convertible

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

    

horat1us / php-xml-convertible example snippets



namespace Horat1us\Examples;

use Horat1us\XmlConvertible;
use Horat1us\XmlConvertibleInterface;

class Person implements XmlConvertibleInterface
{
    use XmlConvertible;

    public $name;

    public $surname;

    public static function fromJson(string $json): Person
    {
        $array = json_decode($json, true);

        $object = new static;
        $object->name = $array['name'] ?? null;
        $object->surname = $array['surname'] ?? null;

        return $object;
    }
}



orat1us\Examples\Person;

$document = new \DOMDocument;
$element = Person::fromJson('{"name": "Alexander", "surname": "Letnikow"}')->toXml($document);
$document->appendChild($element);
echo $document->saveXml();
 



orat1us\Examples\Person;

$xml = '<?xml version="1.0"
bash
composer