public void write(Writer out) {
        try {
            out.write("<!DOCTYPE " + document.getRoot().getName());
            if (getIdentifierDeclaration() != null) {
                out.write(" " + identifierDeclaration.name());
            }
            if (getPublicIdentifier() != null && !getPublicIdentifier().equals("")) {
                out.write(" \"" + getPublicIdentifier() + "\"");
            }
            if (getDtd() != null && !getDtd().equals("")) {
                out.write(" \"" + getDtd() + "\"");
            }
            if (!getEntityMap().isEmpty()) {
                out.write(" [");
                for (String key : getEntityMap().keySet()) {
                    out.write(" <!ENTITY " + key + " \"" + getEntityMap().get(key) + "\"> ");
                }
                out.write("]");
            }
            out.write(">");
        } catch (IOException ex) {
            throw new XmlException("Writing XML failed", ex);
        }
    }