brian0000 Posted February 8, 2011 Share Posted February 8, 2011 My PHP code is generating XML with a blank first line before the <?xml version="1.0" ?> see http://urbanbees.co.uk/maps/phpsqlajax_genxml3.php I have been told this is the reason why my map is not showing the markers in chrome and FF but it is OK in IE8. see http://urbanbees.co.uk/maps/map_of_hive_locations_update.htm You'll either see markers or not depending on your broswer. How do I change the code to not generate this first blank line. Here is the php code. <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("markers"); $parnode = $dom->appendChild($node); // 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 markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $dom->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("name",$row['name']); $newnode->setAttribute("address", $row['address']); $newnode->setAttribute("lat", $row['lat']); $newnode->setAttribute("lng", $row['lng']); $newnode->setAttribute("type", $row['type']); } echo $dom->saveXML(); ?> Link to comment https://forums.phpfreaks.com/topic/227101-xml-generated-by-php-with-blank-first-line-of-xml/ Share on other sites More sharing options...
johnny86 Posted February 9, 2011 Share Posted February 9, 2011 I just cant see where the blank could come.. But if that's the problem you could try: echo ltrim($dom->saveXML); // To get rid of spaces at the begining of the string Link to comment https://forums.phpfreaks.com/topic/227101-xml-generated-by-php-with-blank-first-line-of-xml/#findComment-1171607 Share on other sites More sharing options...
brian0000 Posted February 9, 2011 Author Share Posted February 9, 2011 Thanks Not sure if your line of code was to replace echo $dom->saveXML(); but I tried it both replacing that line of code and by adding the line of code below it and above it. Neither worked tosolve the problem. Thanks for the suggestion. Cheers Link to comment https://forums.phpfreaks.com/topic/227101-xml-generated-by-php-with-blank-first-line-of-xml/#findComment-1171616 Share on other sites More sharing options...
johnny86 Posted February 9, 2011 Share Posted February 9, 2011 Well then the problem isn't in that script because ltrim will get rid of the white space... Have you looked into your template / helpers or whatever might be building stuff for your site? Link to comment https://forums.phpfreaks.com/topic/227101-xml-generated-by-php-with-blank-first-line-of-xml/#findComment-1171620 Share on other sites More sharing options...
brian0000 Posted February 9, 2011 Author Share Posted February 9, 2011 I have found the problem. There was a space after the end of the php code in 'phpsqlajax_dbinfo.php' which was called from the above code. Taking away the space after the ?> solved the issue. Cheers Link to comment https://forums.phpfreaks.com/topic/227101-xml-generated-by-php-with-blank-first-line-of-xml/#findComment-1171712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.