Filtering <img/> elements.

exercise No. 64

Q:

Consider the following XHTML document instance example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <h1>Some Title</h1>
        <!-- Block level image -->

        <div>
            <img src="dsfcjws.jpeg"/> 
        </div>

        <img src="someimage.png"/> 

        <!-- inline image within a paragraph -->
        <p>This is an <em><img src="fds.gif"/></em> inline image:<img
                                                   src="otherdata.png"/>.</p>

    </body>
</html>

First block level image.

Second block level image.

First inline image.

Second inline image.

We will assume:

  1. All <img/> elements having either <body/>, <div/>, <th/> or <td/> parent elements are considered to be block level images.

  2. All remaining <img/> elements are to be considered inline.

Write a SAX application which counts both the number of block level and inline images separately. On invocation the above instance shall yield the following output:

Document contains 2 block level <img> elements.
Document contains 2 inline <img> elements.

Write your application in a testable fashion and provide unit test(s).

A: