<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');

?>

Recommended Answers

All 5 Replies

Member Avatar for diafol

This 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 more threads until this line of questioning and answering has been exhausted. If your question is on a totally different point and nothing to do with snippets of code you have already posted, fine, but otherwise, just leave the 'Start New Discussion' button alone.

Sory Sir

can u Help Me to solve this ....:-(

Member Avatar for diafol

Unfortunately 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 a bit of a slap to the face. Hopefully he (or somebody else) will come along.

yup it's my mistake ..so next time i memoried it...

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.