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