In this recipe, you will see the use of PHP's DOM extension to read an XML and extract information from it. We will create an example where we will display a list of books. Clicking a book name will reveal the list of stories in that book.
Create a folder
Recipe4 in the
Chapter3 directory and make sure you have
common.xml file accessible.
index.phpfile in the
Recipe4folder. In the HTML markup, write the PHP code that will load the XML using DOM methods. From the loaded XML, create
h1sections that will contain the book name and its publication year.
h1, create an unordered list of stories in that book. Note that in the
<head>section, we have hidden