mysql - Error parsing attribute when generating XML from PHP -
i trying implement google map in website using data in mysql ended getting error
this page contains following errors:
error on line 1 @ column 18: error parsing attribute name
below rendering of page first error.
below code provided by: https://developers.google.com/maps/documentation/javascript/mysql-to-maps
may know causing error?
<?php require("connect.php"); function parsetoxml($htmlstr) { $xmlstr=str_replace('<','<',$htmlstr); $xmlstr=str_replace('>','>',$xmlstr); $xmlstr=str_replace('"','"',$xmlstr); $xmlstr=str_replace("'",''',$xmlstr); $xmlstr=str_replace("&",'&',$xmlstr); return $xmlstr; } // opens connection mysql server $connection=mysql_connect ('localhost', $username, $password); if (!$connection) { die('not connected : ' . mysql_error()); } // set active mysql database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('can\'t use db : ' . mysql_error()); } // select rows in markers table $query = "select * markers 1"; $result = mysql_query($query); if (!$result) { die('invalid query: ' . mysql_error()); } header("content-type: text/xml"); // start xml file, echo parent node echo '<markers>'; // iterate through rows, printing xml nodes each while ($row = @mysql_fetch_assoc($result)){ // add xml document node echo '<marker '; echo 'id="' . $ind . '" '; echo 'name="' . parsetoxml($row['name']) . '" '; echo 'address="' . parsetoxml($row['address']) . '" '; echo 'lat="' . $row['lat'] . '" '; echo 'lng="' . $row['lng'] . '" '; echo 'type="' . $row['type'] . '" '; echo '/>'; } // end xml file echo '</markers>'; ?>
it looks example wrong.
echo 'id="' . $ind . '" ';
should
echo 'id="' . $row['id'] . '" ';
(failing try removing error suppression mysql_fetch_assoc
call see if database throwing error. i.e. remove @
)
in either case happening this.
you outputting xml document, document being rendered -
error on line 1 @ column 18: error parsing attribute name
because xml malformed @ name attribute
- tell me have php error in xml output.
e.g.
<markers> <marker id="notice: undefined variable: "id" in ~\whatever\kml.php on line blah blah blah " name="foo" address="bar" ... />}
you can confirm calling file via curl or similar, or "viewing source" in browsers.
finally if isn't case try turning on error reporting @ top of file right after opening php tag, eg.
<?php ini_set('display_errors', 1); error_reporting(~0);
then checking actual output of script again.
Comments
Post a Comment