Jump to content

XML Extra Content Error


mouseywings

Recommended Posts

So I'm generating an XML response for Google Maps and this is how my method looks:

/*
	 * Generate XML for google maps
	 * @param results      Database results array
	*/
	public function generate_xml(array $results) {

		// Start XML file, create parent node
		$dom = new DOMDocument("1.0");
		$node = $dom->createElement("markers");
		$parnode = $dom->appendChild($node);

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

		/*
		 * Iterate through the rows, adding XML nodes for each
		 * Have to do it the ugly way so results aren't pulled twice
		 * (xml and php can't be passed within same array because headers are changed)
		*/
		foreach ($results as $row){
		  $node = $dom->createElement("marker");
		  $newnode = $parnode->appendChild($node);
		  $newnode->setAttribute('id', $row['id']);
		  $newnode->setAttribute('logo', $row['logo']);
		  $newnode->setAttribute("name", $row['name']);
		  $newnode->setAttribute("address", $row['address']);
		  $newnode->setAttribute('city', $row['city']);
		  $newnode->setAttribute('state', $row['state']);
		  $newnode->setAttribute('zip', $row['zip']);
		  $newnode->setAttribute('phone', $row['phone']);
		  $newnode->setAttribute('email', $row['email']);
		  $newnode->setAttribute('web_link', $row['web_link']);
		  $newnode->setAttribute("lat", $row['lat']);
		  $newnode->setAttribute("lng", $row['lng']);
		  $newnode->setAttribute("distance", $row['distance']);
		}

		return $dom->saveXML();

	}

However, I'm getting this error:

 

 

 

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.

 

I believe I'm nesting all my nodes correctly... I'm not really understanding where I'm not. Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/290195-xml-extra-content-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.