Array to XML same key issue



I've tried array to xml. I'm newbie. I use that array2xml class. (On http://ift.tt/1zQVTGA)


My array:



$array = array();
$array['main']['head']['id'] = 1;
$array['main']['head']['type'] = 0;
$array['main']['head']['customerid'] = 10001;
$array['main']['address']['city'] = "BB";
$array['main']['address']['country'] = "AA";
$array['main']['orderlines']['line'][0]['prdcode'] = "1A2BC";
$array['main']['orderlines']['line'][0]['qty'] = 5;
$array['main']['orderlines']['line'][1]['prdcode'] = "2C2BC";
$array['main']['orderlines']['line'][1]['qty'] = 3;

$array['main'][0]['attr']['line'][0]['size'] = "100x200";
$array['main'][0]['attr']['line'][0]['color'] = "orange";
$array['main'][0]['attr']['line'][1]['size'] = "50x50";
$array['main'][0]['attr']['line'][1]['color'] = "orange";
$array['main'][1]['attr']['line'][0]['size'] = "75x200";
$array['main'][1]['attr']['line'][0]['color'] = "blue";
$array['main'][1]['attr']['line'][1]['size'] = "10x50";
$array['main'][1]['attr']['line'][1]['color'] = "green";


You can see is here: http://ift.tt/1zQVTGD


I want to result like this:



<?xml version="1.0" encoding="utf-8"?>
<main>
<head>
<id>1</id>
<type>0</type>
<customerid>0</customerid>
</head>
<address>
<city>BB</city>
<country>AA</country>
</address>
<orderlines>
<line>
<prdcode>1A2BC</prdcode>
<qty>5</qty>
</line>
<line>
<prdcode>2C2BC</prdcode>
<qty>3</qty>
</line>
</orderlines>
<attr>
<line>
<size>100x200</size>
<color>orange</color>
</line>
<line>
<size>50x50</size>
<color>orange</color>
</line>
</attr>
<attr>
<line>
<size>75x200</size>
<color>blue</color>
</line>
<line>
<size>10x50</size>
<color>green</color>
</line>
</attr>
</main>


My issue is when I convert PHP array 2 XML I get an error for <attr> tag. The key is not be numeric.


PHP error: Fatal error: Uncaught exception 'Exception' with message '[Array2XML] Illegal character in tag name. tag: 0 in node: main


How can I fix this issue? Thank you for your helps!


No comments:

Post a Comment