I have this json data and would like to convert to xml with php..
[themes] => Array
(
[theme] => Array
(
[0] => Array
(
[name] => dasdasd
[filename] => dasdasd
[isDefault] => 0
)
[1] => Array
(
[name] => dasdasd
[filename] => dasdasd
[isDefault] => 1
)
)
)
now i want to create an xml in this format..
<themes>
<theme>
<name>dasdasd</name>
<filename>dasdasd</filename>
<isDefault>0</isDefault>
</theme>
<theme>
<name>dasdasd</name>
<filename>dasdasd</filename>
<isDefault>1</isDefault>
</theme>
</themes>
But when i process with this
// function defination to convert array to xml
function array_to_xml($template_info, &$xml_template_info) {
foreach($template_info as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_template_info->addChild("$key");
array_to_xml($value, $subnode);
}
else{
array_to_xml($value, $xml_template_info);
}
}
else {
$xml_template_info->addChild("$key","$value");
}
}
}
// initializing or creating array
$template_info = $templateData;
// creating object of SimpleXMLElement
$xml_template_info = new SimpleXMLElement("<?xml version=\"1.0\"?><template></template>");
// function call to convert array to xml
array_to_xml($template_info,$xml_template_info);
//saving generated xml file
$xml_template_info->asXML(dirname(__FILE__)."/manifest.xml") ;
This is what i get..
<themes>
<theme>
<name>dasdasd</name>
<filename>dasdasd</filename>
<isDefault>0</isDefault>
<name>dasdasd</name>
<filename>dasdasd</filename>
<isDefault>1</isDefault>
</theme>
</themes>
How can i fix this? thanks for help.