Allow retrieving the DOCTYPE specified in an existing document as well as specifying the DOCTYPE to use when writing a new one. Closes #13779.