将数组转换成xml
调用语法:
$xml =\backend\models\core\Array2XML::createXML('root_node_name',$PHP_array); echo $xml->saveXML();
例子:
$xmlArray = array( "@attributes" =>[ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema",],"order" => [ 'volweight'=>1,'untread'=>'Abandoned','clcttype'=>[ "@attributes" =>[ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema",'name'=>1,'receiver'=>[ 'street' => 'guangzhou shenzhen nanfdmen','sender'=>[ 'name'=>'Boxing Chen','postcode'=>'518000','country'=>'CN','province'=>440000,'city'=>'440304','company'=>'grandxing Tech','street'=>'8I 6building weipeng zhengzhong rd futian',] ); $xml = \backend\models\core\Array2XML::createXML('orders',$xmlArray); echo $xml->saveXML(); exit;
输出结果为:
<?xml version="1.0" encoding="UTF-8"?> <orders xmlns:xsi="http://www.w3.org/2001/XMLSchema"> <order> <volweight>1</volweight> <untread>Abandoned</untread> <clcttype xmlns:xsi="http://www.w3.org/2001/XMLSchema"> <name>1</name> </clcttype> <receiver> <street>guangzhou shenzhen nanfdmen</street> </receiver> <sender> <name>Boxing Chen</name> <postcode>518000</postcode> <country>CN</country> <province>440000</province> <city>440304</city> <company>grandxing Tech</company> <street>8I 6building weipeng zhengzhong rd futian</street> </sender> </order> </orders>原文链接:https://www.f2er.com/xml/295814.html