For sake of simplicity, I'm glossing over comments (<!- ... ->), processing instructions (<?xml version='1.0'>), and declarations (<!ELEMENT ...>, <!DOCTYPE ...>). And I'm not bothering to distinguish entity references (&lt;, &#64;) or CDATA sections (<![CDATA[ ...]]>) from normal text.