PHP code example of thenorthmemory / xml
1. Go to this page and download the library: Download thenorthmemory/xml library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thenorthmemory / xml example snippets
use TheNorthMemory\Xml\Transformer;
$array = Transformer::toArray('<xml><hello>world</hello></xml>');
// print_r($array);
// Array
// (
// [hello] => world
// )
$xml = Transformer::toXml($array);
// print_r($xml);
// <xml><hello>world</hello></xml>
$xml = <<<TencentCOSRequest
<Request>
<Operation>
<WatermarkTemplateId>t146d70eb241c44c63b6efc1cc93ccfc5d</WatermarkTemplateId>
<WatermarkTemplateId>t12a74d11687d444deba8a6cc52051ac27</WatermarkTemplateId>
</Operation>
</Request>
TencentCOSRequest;
$array = Transformer::toArray($xml);
// Array
// (
// [Operation] => Array
// (
// [WatermarkTemplateId] => Array
// (
// [0] => t146d70eb241c44c63b6efc1cc93ccfc5d
// [1] => t12a74d11687d444deba8a6cc52051ac27
// )
// )
// )
$xml1 = Transformer::toXml($array, true, true, 'Request');
// print_r($xml1);
// <Request>
// <Operation>
// <WatermarkTemplateId>
// <item>t146d70eb241c44c63b6efc1cc93ccfc5d</item>
// <item>t12a74d11687d444deba8a6cc52051ac27</item>
// </WatermarkTemplateId>
// </Operation>
// </Request>
$array['Operation']['WatermarkTemplateId'] = Transformer::wrap($array['Operation']['WatermarkTemplateId'], true, 'WatermarkTemplateId');
$xml2 = Transformer::toXml($array, true, true, 'Request');
// print_r($xml2);
// <Request>
// <Operation>
// <WatermarkTemplateId>t146d70eb241c44c63b6efc1cc93ccfc5d</WatermarkTemplateId>
// <WatermarkTemplateId>t12a74d11687d444deba8a6cc52051ac27</WatermarkTemplateId>
// </Operation>
// </Request>