xml encoder and html generator
use composer to add MicroEncode to your PHP project:
composer require katmore/micro-encode
- Encoding data to XML - XmlEncoder Usage
- Generating HTML from data - HtmlEncoder 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>
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>: <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>: <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
coverage.txt
: unit test coverage reportphpunit.xml
: PHPUnit configuration filetests/Unit
: source code for 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
MicroEncode - https://github.com/katmore/micro-encode
Copyright (c) 2012-2018 Doug Bird. All Rights Reserved.
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.