protected void writeDocType(String type, String systemId, String publicId) throws XPathException {
        try {
            if (declarationIsWritten && !indenting) {
                // don't add a newline if indenting, because the indenter will already have done so
                writer.write("\n");
            }
            writer.write("<!DOCTYPE " + type + '\n');
            String quotedSystemId = null;
            if (systemId != null) {
                if (systemId.contains("\"")) {
                    quotedSystemId = "'" + systemId + "'";
                } else {
                    quotedSystemId = '"' + systemId + '"';
                }
            }
            if (systemId!=null && publicId==null) {
                writer.write("  SYSTEM " + quotedSystemId + ">\n");
            } else if (systemId==null && publicId!=null) {     // handles the HTML case
                writer.write("  PUBLIC \"" + publicId + "\">\n");
            } else {
                writer.write("  PUBLIC \"" + publicId + "\" " + quotedSystemId + ">\n");
            }
        } catch (java.io.IOException err) {
            throw new XPathException(err);
        }
    }