Exemplo n.º 1
0
/** @todo Rewrite this function (use wbxml_tree_node_* functions) */
WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_xml_elt_with_attrs_and_text(WBXMLTree *tree,
                                                                          WBXMLTreeNode *parent,
                                                                          WB_UTINY *name,
                                                                          const WB_UTINY **attrs,
                                                                          const WB_UTINY *text,
                                                                          WB_ULONG len)
{
    WBXMLTreeNode *new_node = NULL;
    
    /* Add XML node */
    if ((new_node = wbxml_tree_add_xml_elt_with_attrs(tree, parent, name, attrs)) == NULL)
        return NULL;
    
    /* Add text node */
    if ((text != NULL) && (len > 0)) {
        if (wbxml_tree_add_text(tree, new_node, text, len) == NULL) {
            wbxml_tree_node_destroy(new_node);
            return NULL;
        }
    }
    
    return new_node;
}
Exemplo n.º 2
0
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;
    }
}