XML file creation using PHP [closed]

SAFT93

New Member
\[quote\] Possible Duplicate:
XML formatting is not working well \[/quote\]I am trying to create an XML file from the database. Database contains name, phone no and sex. I would like to get all the users' details in a well-formatted XML file. But I am getting now:\[code\]<CUSTOMERS> <name>AAA</name> <name>BBB</name></CUSTOMERS>\[/code\]This is my code:\[code\]$xmlstr = "<?xml version='1.0' ?>\n"."<CUSTOMERS></CUSTOMERS>";$xml = new SimpleXMLElement($xmlstr);while($b=$result->fetch_assoc()){$xml->addChild("name", $b['name']);}return $xml->asXML();\[/code\]I would like to get the out put as shows below\[code\]<CUSTOMERS><AAAA><name>AAA</name><phone>111</phone><sex>male</sex></AAA><BBBB><name>BBB</name><phone>222</phone><sex>female</sex></AAA></CUSTOMERS>\[/code\]Latest Code\[code\] $xmlstr = "<?xml version='1.0' ?>\n"."<CUSTOMERS></CUSTOMERS>"; $xml = new SimpleXMLElement($xmlstr); while($b=$result->fetch_assoc()){ $customer = $xml->addChild("customer"); $customer->addChild("name", $b['name']); $customer->addChild("phone", $b['phone']); $customer->addChild("sex", $b['sex']); //$xml->addChild("place", $b['place']); } return $xml->asXML();\[/code\]
 
Back
Top