0

Getting error message:

"This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error."

require("login.php");

// Start XML file, create parent node
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement('battle');
$dom->appendChild($element);

// Opens a connection to a MySQL server
$connection=mysql_connect ('mysql5.cems.uwe.ac.uk', $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 battle table
$query = "SELECT * FROM battle";
$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 = $doc->create_element("battle");
  $newnode = $parnode->append_child($node);

  $newnode->set_attribute("battle_id", $row['battle_id']);
  $newnode->set_attribute("battle_title", $row['battle_title']);
  $newnode->set_attribute("date", $row['date']);
  $newnode->set_attribute("location", $row['location']);
  $newnode->set_attribute("description", $row['description']);
  $newnode->set_attribute("latitude", $row['latitude']);
  $newnode->set_attribute("longitude", $row['longitude']);
  $newnode->set_attribute("outcome", $row['outcome']);
}

$xmlfile = $doc->dump_mem();
echo $xmlfile;
A.L
  • 10,259
  • 10
  • 67
  • 98
Sam Ager
  • 3
  • 1
  • See [THIS](http://stackoverflow.com/questions/4544272/error-on-line-2-at-column-1-extra-content-at-the-end-of-the-document) – lmarcelocc Mar 02 '15 at 16:17
  • 1
    Check the page source in your browser. It will show you additional charatcers and not just your XML. Specifically at "line 2 column 1" ;) – ToBe Mar 02 '15 at 16:43
  • That looks like a mix of calls to the current DOMDocument and the old PHP 4 DOM implementation. I think PHP shows an HTML error message. (That is not valid XML.) – ThW Mar 02 '15 at 18:28
  • Welcome to Stack Overflow! I edited the title of your question to include the error and moved the error in a blockquote – A.L Mar 06 '15 at 18:40

0 Answers0