27.10.2015 Views

AJAX and PHP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3<br />

// create the element<br />

$book = $dom->createElement('book');<br />

$book->appendChild($title);<br />

$book->appendChild($isbn);<br />

// append as a child of <br />

$books->appendChild($book);<br />

// build the XML structure in a string variable<br />

$xmlString = $dom->saveXML();<br />

// output the XML string<br />

echo $xmlString;<br />

?><br />

5. First let's do a simple test to see what phptest.php returns. Load<br />

http://localhost/ajax/foundations/php/phptest.php in your web browser to<br />

ensure it generates a well-formed XML structure:<br />

Figure 3.1: Simple XML Structure Generated by <strong>PHP</strong><br />

If you don't get the expected result, be sure to check not only the code, but also your <strong>PHP</strong><br />

installation. See Appendix A for details about how to correctly set up your machine.<br />

69<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!