html: process the states in separate functions

This change moves the XML event processing for the different states
into a function per state.

This has several advantages:

  1.  It makes the read() method and the state handlers clear and
      simple, performing a single function.

  2.  It reduces the indentation level, making the code easier to
      read.

  3.  It keeps the data related to processing a state confined to
      that state, avoiding polluting other state handlers.