\backend\models\core\Array2XML

前端之家收集整理的这篇文章主要介绍了\backend\models\core\Array2XML前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

将数组转换成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>

猜你在找的XML相关文章