in reply to xml processing line-by-line

If you know what the root tag is then checking whether the current line contains the closing root tag is trivial. Even if there are several posibilities (as long as none of them can appear as a nonroot tag under a different root).