devtoolboxuk / xml
XML Service
Installs: 3 251
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.16
- ext-xmlwriter: >=0.1
Requires (Dev)
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
License
MIT © DevToolboxUK