Hi All
Can anyone please help me to format my XML by using PHP, there are NO errors in my code but I need to output the result in this format.
[CODE]<states>
<state name=”Alaska” colour=”#ff0000″>
<point lat=”70.0187″ lng=”-141.0205″/>
<point lat=”70.1292″ lng=”-141.7291″/>
<point lat=”70.0187″ lng=”-141.0205″/>
</state>
</states>
This is my php code and output.
[code=php]$query = “SELECT u.uname, a.pcode1, a.latitude, a.county, a.longitude FROM crm_geo_area_allocs c, crm_geo_areas a, crmusers u
WHERE c.uid = u.uid
AND c.pcode1 = a.pcode1”;
$result = mysqli_query ($dbh, $query ) or die ( mysqli_error () );
$xml = new SimpleXMLElement(‘<xml/>’);
while($row = mysqli_fetch_assoc($result)) {
$draw = $xml->addChild(‘location’);
$draw->addChild(‘uname’,$row[‘uname’]);
$draw->addChild(‘colour’,$row[‘colour’]);
$draw->addChild(‘postcode’,$row[‘pcode1’]);
$draw->addChild(‘county’,$row[‘county’]);
$draw->addChild(‘latitude’,$row[‘latitude’]);
$draw->addChild(‘longitude’,$row[‘longitude’]);
}
mysqli_close($dbh);
$fp = fopen(“get_locationsXML.xml”,”wb”);
fwrite($fp,$xml->asXML());
fclose($fp);
The output.
[CODE]<xml>
<location>
<uname>Bruce Brassington</uname>
<colour/>
<postcode>LS10</postcode>
<county>Leeds</county>
<latitude>53.7653</latitude>
<longitude>-1.53195</longitude>
</location>
</xml>