Reading an XML using DOM extension
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.
Getting ready
Create a folder Recipe4
in the Chapter3
directory and make sure you have common.xml
file accessible.
How to do it...
Create an
index.php
file in theRecipe4
folder. In the HTML markup, write the PHP code that will load the XML using DOM methods. From the loaded XML, createh1
sections that will contain the book name and its publication year.Under each
h1,
create an unordered list of stories in that book. Note that in the<head>
section, we have hiddenul
usingdisplay
property. Therefore, on the page only book names will be visible.<html> <head> <title>Using DOM</title> <style type="text/css"> h1{ cursor:pointer;font-size:20px;} ul{ display:none; list...