1. Go to this page and download the library: Download jolti/dtotoxml 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/ */
jolti / dtotoxml example snippets
use Dtotoxml\XmlSerializer;
use Dtotoxml\Configuration;
use Samples\Dto\School;
use Samples\Dto\SchoolFixtures;
$xmlSerialize = new XmlSerializer();
// Configure the serializer
$config = new Configuration();
$config->setHead('<?xml version="1.0"
$school = SchoolFixtures::createSchool();
$xml = $xmlSerialize->format($xmlSerialize->serialise($school));
// Output the XML
echo '<pre>', htmlentities($xml), '</pre>';
namespace Samples\Dto;
class School
{
private $name;
private $adresse;
private $teachers;
private $rooms;
public function getAttributes(): array
{
return ["name"];
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getAdresse(): Adresse
{
return $this->adresse;
}
public function setAdresse(Adresse $adresse): void
{
$this->adresse = $adresse;
}
public function getTeachers(): array
{
return $this->teachers;
}
public function setTeachers(array $teachers): void
{
$this->teachers = $teachers;
}
public function getRooms(): array
{
return $this->rooms;
}
public function setRooms(array $rooms): void
{
$this->rooms = $rooms;
}
}