Studying more of the eXpat XML parser as vendored into Papyrix...
The primary parser state might transition to a CData state. It invokes a helper propagating any errors before deciding whether to switch to the external-entity state or that primary state. Normalizes its input, iterates over the lexed XML tokens possibly invoking another helper to help clean up, & branches over results to clean up. Primarily its looks for cdata-sect-close tokens, converting others to text.
1/?