note
Abigail-II
What defines "improper" nesting? Your example suggests no nesting is allowed at all. Is that the case? Anyway, I'd use a single tokenizer and a counter. Whenever you see a <code><sec id = "..."></code> token, increment the counter. Whenever you see a <code></sec></code> token, decrement the counter. Whenver the counter has a value unequal to either 0 or 1, you have "improper nesting" - that is, assuming no nesting at all can happen.
<p>
Abigail
368757
368757