Filtering <img/> elements.

exercise No. 64


Consider the following XHTML document instance example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:html=""
        <h1>Some Title</h1>
        <!-- Block level image -->

            <img src="dsfcjws.jpeg"/> 

        <img src="someimage.png"/> 

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


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).