mouseywings Posted July 30, 2014 Share Posted July 30, 2014 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! Quote Link to comment Share on other sites More sharing options...
mogosselin Posted July 30, 2014 Share Posted July 30, 2014 Can you show us the code where you call the function? You could have an extra character at the end of your file like in this SO post? http://stackoverflow.com/questions/8850120/extra-content-at-the-end-of-the-document-php-and-xml Quote Link to comment Share on other sites More sharing options...
Maq Posted July 31, 2014 Share Posted July 31, 2014 Show us the XML being generated. It sounds like you are not terminating a tag correctly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.