$sql = "SELECT * FROM users ORDER BY RAND() LIMIT 100";
$xml = new SimpleXMLElement('<xml/>');
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_array()) {
$users = $xml->addChild('users');
$users->addChild('Id',$row['sno']);
$users->addChild('lat',$row['lat']);
$users->addChild('long',$row['lng']);
$users->addChild('address',$row['address']);
}
$conn->close();
//Create the XML file
$fp = fopen("users100r.xml","wb");
//Write the XML nodes
fwrite($fp,$xml->asXML());
fclose($fp);
echo $xml->saveXML();
?>
I want to create an XML file using the above code, but the problem is that it did not generate a required structure, which I actually needed.
I need an XML file with following structure. How can I generate it?
<users>
<point id="1" lat="24.24707031" lng="68.16540527" address="Pakistan"/>
<point id="2" lat="34.24707031" lng="63.16540527" address="Lahore"/>
<point id="3" lat="28.24707031" lng="55.16540527" address="Karachi"/>
</users>