This is how it should be modified (overlapping what have been advised).
[1] If you want to use
String s uniformly and generally in the handler, move the declaration outside of the startElement handling.
[2] In the same spirit of electing the flags in the startElement() because the detection in all cases of interested is on the element's name,
you should take down the flags in the endElement().
[3] Flags shouldn't be switched in the characters handling.