Jump to content

[SOLVED] XML DomDocument probs


schilly

Recommended Posts

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;
?>

Link to comment
https://forums.phpfreaks.com/topic/166355-solved-xml-domdocument-probs/
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.