This is a long way from actually parsing anything; it just raises an exception if the document is invalid. Nor is it likely to be particularly efficient, due to heavy use of blocks and throw/catch.