void wbxml_tree_clb_xml_doctype_decl(void           *ctx,
                                     const XML_Char *doctypeName,
                                     const XML_Char *sysid,
                                     const XML_Char *pubid,
                                     int             has_internal_subset)
{
    WBXMLTreeClbCtx *tree_ctx = (WBXMLTreeClbCtx *) ctx;
    const WBXMLLangEntry *lang_table = NULL;

    (void) doctypeName;         /* avoid warning about unused parameter */
    (void) has_internal_subset; /* avoid warning about unused parameter */

    if (tree_ctx->expat_utf16) {
        /** @todo Convert from UTF-16 to UTF-8 */
    }

    /* Search for Language Table, given the XML Public ID and System ID */
    lang_table = wbxml_tables_search_table(wbxml_tables_get_main(),
                                           (const WB_UTINY *) pubid,
                                           (const WB_UTINY *) sysid,
                                           NULL);

    if (lang_table != NULL) {
        /* Ho Yeah ! We got it ! */
        tree_ctx->tree->lang = lang_table;
    }
    else {
        /* We will try to find the Language Table, given the Root Element */
        WBXML_WARNING((WBXML_CONV, "Language Table NOT found, given the XML Public ID and System ID"));
    }
}
Exemple #2
0
const WBXMLLangEntry * wbxml_tables_get_table(WBXMLLanguage lang)
{
    const WBXMLLangEntry *main_table = NULL;
    WB_ULONG index = 0;
    
    /* Get main tables array*/
    if ((lang == WBXML_LANG_UNKNOWN) || ((main_table = wbxml_tables_get_main()) == NULL))
        return NULL;
    
    /* Search language table */
    while (main_table[index].langID != WBXML_LANG_UNKNOWN) {
        if (main_table[index].langID == lang)
            return &main_table[index];
        index++;
    }

    return NULL;
}
void wbxml_tree_clb_xml_start_element(void           *ctx,
                                      const XML_Char *localName,
                                      const XML_Char **attrs)
{
    WBXMLTreeClbCtx *tree_ctx = (WBXMLTreeClbCtx *) ctx;
    const WBXMLLangEntry *lang_table = NULL;

    WBXML_DEBUG((WBXML_PARSER, "Expat element start callback ('%s')", localName));

    if (tree_ctx->expat_utf16) {
        /** @todo Convert from UTF-16 to UTF-8 */
    }

    /* Check for Error */
    if (tree_ctx->error != WBXML_OK)
        return;

    /* Are we skipping a whole node ? */
    if (tree_ctx->skip_lvl > 0) {
        tree_ctx->skip_lvl++;
        return;
    }

    if (tree_ctx->current == NULL) {
        /* This is the Root Element */
        if (tree_ctx->tree->lang == NULL) {
            /* Language Table not already found: Search again */
            lang_table = wbxml_tables_search_table(wbxml_tables_get_main(),
                                                   NULL,
                                                   NULL,
                                                   (const WB_UTINY *) localName);

            if (lang_table == NULL) {
                /* Damn, this is an unknown language for us... */
                tree_ctx->error = WBXML_ERROR_UNKNOWN_XML_LANGUAGE;
                return;
            }
            else {
                /* Well, we hope this was the Language we are searching for.. let's try with it :| */
                tree_ctx->tree->lang = lang_table;
            }
        }
    }

#if defined( WBXML_SUPPORT_SYNCML )

    /* If this is an embedded (not root) document, skip it
     * Actually SyncML DevInf and DM DDF are known as such
     * potentially embedded documents.
     */
    if ((
                (WBXML_STRCMP(localName, "syncml:devinf:DevInf") == 0) ||
                (WBXML_STRCMP(localName, "syncml:dmddf1.2:MgmtTree") == 0)
            )&&
            (tree_ctx->current != NULL))
    {
        tree_ctx->skip_start = XML_GetCurrentByteIndex(tree_ctx->xml_parser);

        /* Skip this node */
        tree_ctx->skip_lvl++;

        return;
    }

#endif /* WBXML_SUPPORT_SYNCML */

    /* Add Element Node */
    tree_ctx->current = wbxml_tree_add_xml_elt_with_attrs(tree_ctx->tree,
                        tree_ctx->current,
                        (WB_UTINY *) localName,
                        (const WB_UTINY**) attrs);

    if (tree_ctx->current == NULL) {
        tree_ctx->error = WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }
}