<root>
<item0><courseId>133</courseId></item0>
<item1><question>What is php?</question></item1>
<item2><ansIndex>1</ansIndex></item2>
<item3><ans>Sever Side Lang.</ans></item3>
<item4><ans>Web Lang.</ans></item4>
<item5><ans>NOne</ans></item5>
<item6><ans>Both</ans></item6>
</root>
My Xml Function Give This Type Of Output..Bt i Want
<root>
<courseId>133</courseId>
<question>What is php?</question>
<ansIndex>1</ansIndex>
<ans>Sever Side Lang.</ans>
<ans>Web Lang.</ans>
<ans>NOne</ans>
<ans>Both</ans>
</root>
This is my Xml Function ..
$array = json_decode($_GET['data'],true);
function array_to_xml($array, &$xml_user_info) {
foreach($array as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_user_info->addChild("$key");
array_to_xml($value, $subnode);
}else{
$subnode = $xml_user_info->addChild("item$key");
array_to_xml($value, $subnode);
}
}else {
$xml_user_info->addChild("$key",htmlspecialchars("$value"));
}
}
}
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><root></root>");
array_to_xml($array,$xml_user_info);
$xml_file = $xml_user_info->asXML('users.xml');
if($xml_file){
echo 'XML file have been generated successfully.';
}else{
echo 'XML file generation error.';
}
N also I Want Set Attribute In ans Tag..
example ...if ansIndex is 1 So i want set one attribute in first ans tag 'right'.