XML Service

1.0.5 2018-11-04 13:47 UTC

This package is auto-updated.

Last update: 2024-11-13 22:42:15 UTC


README

Basic write XML Service from an Array, and a read XML service to an Array

TODO - Connect to Travis

Table of Contents

Background

Used to create and read XML files

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