Validate/Verify HTML File's Proper Nesting of Tags

Problem Description

Create a program that reads a HTML file and verifies that for every start tag there is an end tag and that they are properly nested. Report any anomalies. Also report the number of of each tag. (Print the tag count statistics sorted by tag name.)

An example of a pair of tags is, the start tag "<p>" has an end tag "</p>".

it is important to note that some tags do not have an end tag. For example, "<img ...... />".

Things to Think About

Example of properly nested tags

Note: indentation is not required. It is there to show nesting.

<h1>.....</h1>
   <img ..../>
   <p>
      <b>......</b>  
   </p>
   <div>
      <div>
         <p>
         </p>
      </div>
   </div>

Example of tags that are not properly nested

Note: indentation is not required. It is there to show nesting.

<h1>.....</h1>
   <p>
      <b>...... 
   </p>
      </b>                 <--- wrong nesting
   <p>                     <--- no end tag
   <div>
      <p>
      <div>
         </p>              <--- wrong nesting
      </div>
   </div>