1. A method of checking whether an XML document is well-formed, the method comprising: receiving contents of the XML document; generating a plurality of tokens based on the contents of the XML document; determining an element depth of each of the plurality of tokens; calculating a maximum depth of the XML document based on the depths of each of the plurality of tokens; rejecting the XML document if the maximum depth exceeds a predetermined depth.