DOM & SAX Tutorial Exercises

  1. The following XML document (house.xml) contains details of properties on an Estate Agent's list.
    <?xml version="1.0"?>
    <Properties>
       <House>
          <Address>34 West Street</Address>
          <Room>hall</Room>
          <Room>kitchen</Room>
          <Room>lounge</Room>
          <Room>bedroom</Room>
          <Room>bedroom</Room>
          <Room>bathroom</Room>
       </House>
       <House>
          <Address>24 North Street</Address>
          <Room>hall</Room>
          <Room>kitchen</Room>
          <Room>lounge</Room>
          <Room>sitting room</Room>
          <Room>study</Room>
          <Room>bedroom</Room>
          <Room>bathroom</Room>
       </House>
       <House>
          <Address>14 South Street</Address>
          <Room>hall</Room>
          <Room>kitchen</Room>
          <Room>bedroom</Room>
          <Room>bedroom</Room>
          <Room>bathroom</Room>
          <Garden>40 feet</Garden>
       </House>
       <House>
          <Address>99 East Street</Address>
          <Room>hall</Room>
          <Room>kitchen</Room>
          <Room>bedroom</Room>
          <Room>bedroom</Room>
          <Room>lounge</Room>
          <Room>bathroom</Room>
       </House>
    </Properties>
    
    Write a PHP program that uses the DOM to display the addresses of all the properties.

    screenshot

  2. Change the PHP you wrote for the previous exercise so that it outputs the number of rooms in each property e.g.

    screenshot

    You may like to use a property of the Node object that tells you the tag name in order to do this. How can you find which Node property to use?
     
  3. Now try the above exercises using JavaScript code on the client.
     
  4. And using SAX.