MOBI_RET mobi_xml_write_dcmeta_date(xmlTextWriterPtr writer, const OPFdate **date) {
    if (date) {
        size_t i = 0;
        while (i < OPF_META_MAX_TAGS) {
            if (date[i] == NULL || date[i]->value == NULL) {
                break;
            }
            int xml_ret;
            xml_ret = xmlTextWriterStartElementNS(writer, BAD_CAST "dc", BAD_CAST "date", NULL);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            if (date[i]->event) {
                xml_ret = xmlTextWriterWriteAttributeNS(writer, BAD_CAST "opf", BAD_CAST "event", NULL, BAD_CAST date[i]->event);
                if (xml_ret < 0) {
                    debug_print("XML error: %i (date event: %s)\n", xml_ret, date[i]->event);
                    return MOBI_XML_ERR;
                }
            }
            xml_ret = xmlTextWriterWriteString(writer, BAD_CAST date[i]->value);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            xml_ret = xmlTextWriterEndElement(writer);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            i++;
        }
    }
    return MOBI_SUCCESS;
}
MOBI_RET mobi_xml_write_dcmeta_date(xmlTextWriterPtr writer, const OPFdate **date) {
    if (date) {
        size_t i = 0;
        while (i < OPF_META_MAX_TAGS) {
            if (date[i] == NULL || date[i]->value == NULL) {
                break;
            }
            int xml_ret;
            xml_ret = xmlTextWriterStartElementNS(writer, BAD_CAST "dc", BAD_CAST "date", NULL);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            if (date[i]->event) {
                xml_ret = xmlTextWriterWriteAttributeNS(writer, BAD_CAST "opf", BAD_CAST "event", NULL, BAD_CAST date[i]->event);
                if (xml_ret < 0) {
                    debug_print("XML error: %i (date event: %s)\n", xml_ret, date[i]->event);
                    return MOBI_XML_ERR;
                }
            }
            xml_ret = xmlTextWriterWriteString(writer, BAD_CAST date[i]->value);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            xml_ret = xmlTextWriterEndElement(writer);
            if (xml_ret < 0) {
                debug_print("XML error: %i (date value: %s)\n", xml_ret, date[i]->value);
                return MOBI_XML_ERR;
            }
            i++;
        }
    }
    return MOBI_SUCCESS;
}