generate_xml.php - Generate XML: Revision

Last updated by steven
<?php
require("phpsqlajax_dbinfo.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the dropzones table
$query = "SELECT * FROM dropzones WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<dropzones>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<dropzones ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'street="' . parseToXML($row['street']) . '" ';
echo 'city="' . parseToXML($row['city']) . '" ';
echo 'phone="' . parseToXML($row['phone']) . '" ';
echo 'fax="' . parseToXML($row['fax']) . '" ';
echo 'mail="' . parseToXML($row['mail']) . '" ';
echo 'internet="' . parseToXML($row['internet']) . '" ';
echo 'latitude="' . $row['latitude'] . '" ';
echo 'longitude="' . $row['longitude'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}

// End XML file
echo '</dropzones>';

?>...

History