MOBI_RET mobi_write_ncx_header(xmlTextWriterPtr writer, const OPF *opf, uint32_t maxlevel) {
    /* write header */
    char depth[10 + 1];
    snprintf(depth, 11, "%d", maxlevel);

    /* <head> */
    int xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "head");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    /* meta uid */
    MOBI_RET ret = mobi_xml_write_meta(writer, "dtb:uid", opf->metadata->dc_meta->identifier[0]->value);
    if (ret != MOBI_SUCCESS) { return ret; }
    /* meta depth */
    ret = mobi_xml_write_meta(writer, "dtb:depth", depth);
    if (ret != MOBI_SUCCESS) { return ret; }
    /* meta pagecount */
    ret = mobi_xml_write_meta(writer, "dtb:totalPageCount", "0");
    if (ret != MOBI_SUCCESS) { return ret; }
    /* meta pagenumber */
    ret = mobi_xml_write_meta(writer, "dtb:maxPageNumber", "0");
    if (ret != MOBI_SUCCESS) { return ret; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    // <docTitle>
    xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "docTitle");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "text");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterWriteString(writer, BAD_CAST opf->metadata->dc_meta->title[0]);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    return MOBI_SUCCESS;
}
MOBI_RET mobi_write_ncx_header(xmlTextWriterPtr writer, const OPF *opf, uint32_t maxlevel) {
     
    char depth[10 + 1];
    snprintf(depth, 11, "%d", maxlevel);

     
    int xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "head");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
     
    MOBI_RET ret = mobi_xml_write_meta(writer, "dtb:uid", opf->metadata->dc_meta->identifier[0]->value);
    if (ret != MOBI_SUCCESS) { return ret; }
     
    ret = mobi_xml_write_meta(writer, "dtb:depth", depth);
    if (ret != MOBI_SUCCESS) { return ret; }
     
    ret = mobi_xml_write_meta(writer, "dtb:totalPageCount", "0");
    if (ret != MOBI_SUCCESS) { return ret; }
     
    ret = mobi_xml_write_meta(writer, "dtb:maxPageNumber", "0");
    if (ret != MOBI_SUCCESS) { return ret; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
     
    xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "docTitle");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterStartElement(writer, BAD_CAST "text");
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterWriteString(writer, BAD_CAST opf->metadata->dc_meta->title[0]);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    xml_ret = xmlTextWriterEndElement(writer);
    if (xml_ret < 0) { return MOBI_XML_ERR; }
    return MOBI_SUCCESS;
}