Fix quotes
Clean up doctype parsing and association to the document

Previously, code that created documents had to set and synchronize doc._doctype, which was error-prone. Now it is just lazily computed.

While there, cleaned up the parseDocType function.