Home >Backend Development >PHP Tutorial >Detailed explanation of 3 methods for PHP to output XML to the page_PHP Tutorial
The first method:
//Create //Create the //Create a title for the book //Create isbn element for book //Create book element //Regard //Create an XML structure in a string variable //Output XML string ?>
$response = $dom->createElement('response');
$dom->appendChild($response);
$books = $dom->createElement('books');
$response->appendChild( $books);
$title = $dom->createElement('title');
$titleText = $dom->createTextNode('PHP and AJAX');
$title->appendChild($titleText);
$isbn = $dom->createElement('isbn');
$isbnText = $dom->createTextNode('1-21258986');
$isbn->appendChild($isbnText);
$book = $dom->createElement('book');
$book->appendChild($title);
$book->appendChild( $isbn);
$books->appendChild($book);
$xmlString = $dom->saveXML();
echo $xmlString;