<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
Recommended Answers
Jump to PostThis is directly related to your last thread. Please keep questions within the thread if they are related. Otherwise you end up flooding the forum.
lps answered your question in this thread:
https://www.daniweb.com/web-development/php/threads/495681/set-attribute-in-xml-daynamically
But you did not reply (again), but simply started a new thread. Please, don't start any …
Jump to PostUnfortunately I'm busy and am only cleaning up forum mess at the moment. Maybe lps will help you, but you may have run the risk of alienating him as starting a new thread instead of responding to a well-crafted solution, which I imagine took some considerable time to write, is …
All 5 Replies
Reply to this topic
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.