Class StrictXHTMLValidator

All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class StrictXHTMLValidator extends ContentHandlerDecorator
A SAX content handler decorator that enforces XHTML well-formedness on the incoming event stream. Any parser that emits an event sequence that would produce malformed XHTML triggers a SAXException synchronously — the stack trace points at the parser code that made the offending call, instead of surfacing later as a parse error on the serialized output.

Invariants enforced:

  • startDocument is called at most once.
  • No SAX events arrive after endDocument.
  • Every endElement matches the topmost open startElement (no cross-nesting like <a><b></a></b>).
  • The element stack is empty when endDocument fires (no unclosed elements left dangling by an exception path).
  • Within a single startElement, no two attributes share the same (namespaceURI, localName) pair (the bug class that produces <div class="x" class="y">).
Use as a decorator wrapping the real handler. It passes every event through to the downstream handler after validation, so any normal text/XHTML capture still works.