devtoolboxuk/engrafo

File Library

1.1.7 2020-09-06 12:02 UTC

This package is auto-updated.

Last update: 2024-11-06 21:41:17 UTC


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

Total Downloads License

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

@DevToolboxUk.

License

MIT © DevToolboxUK