<root>
<question>What is php ?</question>
<ansIndex>0</ansIndex>
<ans>
<0>Server SIde Lang.</0>
<1>client side lang</1>
<2>none</2>
<3>both</3>
</ans>
</root>
//This is my xml File.
// Bt I want When <ansIndex> is 0 then set attribute in <0 true>,<ansIndex> is 1 then <1 true>
//how i can do this?
//my Php code is
<?php
$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');
?>
Vivek_13 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.