devtoolboxuk / engrafo
File Library
Installs: 4 779
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.16
- ext-xmlwriter: >=0.1
- devtoolboxuk/utilitybundle: ~1.0.9
- league/csv: ^7.0
Requires (Dev)
README
Basic file read / write service for CSV, JSON and XML. Write Service writes a file from an Array, and the read service reads a file to an Array
Table of Contents
Background
Usage
Usage of the XML service
$ composer require devtoolboxuk/xml
Then include Composer's generated vendor/autoload.php to enable autoloading:
require 'vendor/autoload.php';
use devtoolboxuk/xml; $this->xmlService = new xmlService();
Write XML Service
Create the Writing XML service
$this->writeXMLService = $this->xmlService->writeXMLService();
Setting the Writing XML root name
By default the root name is root
$this->writeXMLService->setRootName('products');
Example of Writing an XML
Plain XML
echo $this->writeXMLService->createDoc(); echo $this->writeXMLService->endDoc();
<?xml version="1.0" encoding="UTF-8"?> <root> </root>
XML with attributes
echo $this->writeXMLService->createDoc(); echo $this->writeXMLService->endDoc([ '@a' => [ 'xml_version' => '1.0', ] ]);
<?xml version="1.0" encoding="UTF-8"?> <root xml_version="1.0"> </root>
XML with data
echo $this->writeXMLService->createDoc(); echo $this->writeXMLService->create('product',[ '@t'=>[ 'sku'=>12345, 'text'=>'I am text', ] ]); echo $this->writeXMLService->endDoc([ '@a' => [ 'xml_version' => '1.0', ] ]);
<?xml version="1.0" encoding="UTF-8"?> <root xml_version="1.0"> <product> <sku>12345</sku> <text>I am text</text> </product> </root>
Maintainers
License
MIT © DevToolboxUK