schilly Posted July 17, 2009 Share Posted July 17, 2009 I'm having problems outputing this xml to an ajax query. The ajax query is fine(returns 200 OK) but goes into the error callback for some reason. I've narrowed it down to the xml code but can't seem to figure it out. If I comment out all the xml lines after $title->appendChild($dom->createTextNode('Great American Novel')); it works. But if I add anything after that, it breaks. Even my browser says it's bad xml when I load it in the browser and not through ajax. Any suggestions?? <?php header ("content-type: text/xml"); ini_set ("display_errors", "1"); error_reporting(E_ALL); //make sure it was posted $dom = new DomDocument('1.0','utf-8'); //add root - <books> $books = $dom->appendChild($dom->createElement('books')); //add <book> element to <books> $book = $books->appendChild($dom->createElement('book')); //add <title> element to <book> $title = $book->appendChild($dom->createElement('title')); //add <title> text node element to <title> $title->appendChild($dom->createTextNode('Great American Novel')); //login $login = $dom->appendChild($dom->createElement('login')); $loginerror = $login->appendChild($dom->createElement('loginerror')); $loginerror->appendChild($dom->createTextNode('ts_email')); $loginerror = $login->appendChild($dom->createElement('loginerror')); $loginerror->appendChild($dom->createTextNode('ts_password')); //success $success = $dom->appendChild($dom->createElement('success')); $success->appendChild($dom->createTextNode('success')); //errors $errors = $dom->appendChild($dom->createElement('errors')); $error = $errors->appendChild($dom->createElement('Error')); $error->appendChild($dom->createTextNode('ts_name')); $error = $errors->appendChild($dom->createElement('Error')); $error->appendChild($dom->createTextNode('ts_email')); $error = $errors->appendChild($dom->createElement('Error')); $error->appendChild($dom->createTextNode('ts_content')); //generate xml $dom->formatOutput = true; // set the formatOutput attribute of // domDocument to true // save XML as string or file $test1 = $dom->saveXML(); // put string in test1 echo $test1; ?> Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 hmmm safari gives me: error on line 7 at column 1: Extra content at the end of the document Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 ok FF says: XML Parsing Error: junk after document element Line Number 7, Column 1: <login> ^ Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 bah think i figured it out. didn't know you had to have all tags nested. 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.