Jump to content

XML generated by PHP with blank first line of XML


brian0000

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.