Skip to content
master
Go to file
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Jun 4, 2018
May 31, 2018
May 30, 2018
May 31, 2018
May 31, 2018
Dec 6, 2018
May 31, 2018
Dec 6, 2018

README.md

MicroEncode

xml encoder and html generator

Installation

use composer to add MicroEncode to your PHP project:

composer require katmore/micro-encode

Usage

XmlEncoder Usage

The XMLEncoder class serializes an XML document from arbitrary data. The PHP data types supported are: boolean, integer, float, string, array, object, and null. The XML document conforms to the Flat XML Schema specification.

The following is an example of encoding associative array data into an XML document:

$myData = [
   'my_example_1'=>'my 1st data value',
   'my_example_2'=>'my 2nd data value',
];

echo (new \MicroEncode\XmlEncoder($myData));

The above code should output the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<fx:data xmlns:fx="https://github.com/katmore/flat/wiki/xmlns" xmlns="https://github.com/katmore/flat/wiki/xmlns-object" fx:md5="37a6259cc0c1dae299a7866489dff0bd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:extxs="https://github.com/katmore/flat/wiki/xmlns-extxs" xsi:type="extxs:Hashmap">
   <my_example_1 xsi:type="xs:string">my 1st data value</my_example_1>
   <my_example_2 xsi:type="xs:string">my 2nd data value</my_example_2>
</fx:data>

HtmlEncoder Usage

The HtmlEncoder class generates HTML from arbitrary data. The PHP data types supported are: boolean, integer, float, string, array, object, and null.

The following is an example of generating HTML from associative array data:

$myData = [
   'my_example_1'=>'my 1st data value',
   'my_example_2'=>'my 2nd data value',
];

echo (new \MicroEncode\HtmlEncoder($myData));

The above code should output the following HTML:

<ul data-type="array">
   <li data-index="0" data-key="my_example_1" data-role="item"><span data-role="item-key">my_example_1</span>:&nbsp;<span data-role="item-value" data-type="string">my 1st data value</span></li><!--/data-item: (my_example_1)-->
   <li data-index="1" data-key="my_example_2" data-role="item"><span data-role="item-key">my_example_2</span>:&nbsp;<span data-role="item-value" data-type="string">my 2nd data value</span></li><!--/data-item: (my_example_2)-->
</ul>

The above HTML would render into set of unordered list items as follows:

  • my_example_1: my 1st data value
  • my_example_2: my 2nd data value

Unit Tests

To perform unit tests, execute phpunit located in the vendor/bin directory.

vendor/bin/phpunit

The tests.sh wrapper script is provided for convenience.

./tests.sh

Legal

Copyright

MicroEncode - https://github.com/katmore/micro-encode

Copyright (c) 2012-2018 Doug Bird. All Rights Reserved.

License

MicroEncode is copyrighted free software. You may redistribute and modify it under either the terms and conditions of the "The MIT License (MIT)"; or the terms and conditions of the "GPL v3 License". See LICENSE and GPLv3.

You can’t perform that action at this time.