Phalcon XML Annotations is a library that allows you to convert PHP objects into XML files. It provides annotations to define the structure and parameters of XML files based on PHP objects.
You can install the Phalcon XML Annotations library using Composer. Simply run the following command in your project:
composer require i4erkasov/phalcon-xml-annotations
See the example
directory for context.
<?php
use ExamplePhalconXML\IrishPub;
use I4\Phalcon\XML\Analyzer;
use I4\Phalcon\XML\XmlAnnotations;
use Phalcon\Annotations\Adapter\Memory;
$annotations = new XmlAnnotations(
new Analyzer(new Memory())
);
$xml = $annotations->parse(
new IrishPub(
'The Shamrock Pub',
'Dublin, Ireland',
'10:00 AM',
'2:00 AM'
)
);
$xml->setExtraAttributes([
'Beer' => [
'Date' => (new DateTime('now'))->format('Y-m-d'),
]
]);
echo $xml->getString(); // Returns the XML as a string
echo $xml->save('/tmp/file.xml'); // Saves the generated XML to a file
<?xml version="1.0" encoding="UTF-8"?>
<XML>
<IrishPub Name="The Shamrock Pub" Address="Dublin, Irelan" OpeningTime="10:00 AM" ClosingTime="2:00 AM">
<![CDATA[Irish Pub]]>
<BeerList>
<Beer Date="2023-06-02" Brand="Guinness" Type="Stout" ABV="4.2" Country="Ireland"/>
<Beer Date="2023-06-02" Brand="Smithwick's" Type="Red Ale" ABV="4.5" Country="Ireland"/>
<Beer Date="2023-06-02" Brand="Harp Lager" Type="Lager" ABV="4.5" Country="Ireland"/>
</BeerList>
</IrishPub>
</XML>
You can contribute to the development of this library by creating issues, suggesting new features, and submitting pull requests to the GitHub repository.
Phalcon XML Annotations is released under the MIT License.