示例#1
0
WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_attr(WBXMLTreeNode *node,
                                                   WBXMLAttribute *attr)
{
    WBXMLAttribute *new_attr = NULL;

    if ((node == NULL) || (attr == NULL)) {
        return WBXML_ERROR_BAD_PARAMETER;
    }

    /* Create list if needed */
    if (node->attrs == NULL) {
        if ((node->attrs = wbxml_list_create()) == NULL) {
            return WBXML_ERROR_NOT_ENOUGH_MEMORY;
        }
    }

    /* Duplicate Attribute */
    if ((new_attr = wbxml_attribute_duplicate(attr)) == NULL)
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;
    
    /* Add attribute to list */
    if (!wbxml_list_append(node->attrs, new_attr)) {
        wbxml_attribute_destroy(attr);
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }

    return WBXML_OK;
}
示例#2
0
WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_xml_attr(const WBXMLLangEntry *lang_table,
                                                       WBXMLTreeNode *node,
                                                       const WB_UTINY *name,
                                                       const WB_UTINY *value)
{
    WBXMLAttribute *attr = NULL;
    const WBXMLAttrEntry *attr_entry = NULL;

    /* Create list if needed */
    if (node->attrs == NULL) {
        if ((node->attrs = wbxml_list_create()) == NULL) {
            return WBXML_ERROR_NOT_ENOUGH_MEMORY;
        }
    }

    /* Create Attribute */
    if ((attr = wbxml_attribute_create()) == NULL)
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;

    /* Set Attribute Name */
    if ((attr_entry = wbxml_tables_get_attr_from_xml(lang_table, (WB_UTINY *)name, (WB_UTINY *)value, NULL)) != NULL)
        attr->name = wbxml_attribute_name_create_token(attr_entry);
    else
        attr->name = wbxml_attribute_name_create_literal((WB_UTINY *)name);

    if (attr->name == NULL) {
        wbxml_attribute_destroy(attr);
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }

    /* Set Attribute Value */
    attr->value = wbxml_buffer_create_real(value, WBXML_STRLEN(value), WBXML_STRLEN(value));
    if (attr->value == NULL) {
        wbxml_attribute_destroy(attr);
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }

    /* Add attribute to list */
    if (!wbxml_list_append(node->attrs, attr)) {
        wbxml_attribute_destroy(attr);
        return WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }

    return WBXML_OK;
}
示例#3
0
WBXML_DECLARE(WBXMLList *) wbxml_buffer_split_words_real(WBXMLBuffer *buff)
{
    WB_UTINY *p = NULL;
    WBXMLList *list = NULL;
    WBXMLBuffer *word = NULL;
    WB_ULONG i = 0, start = 0, end = 0;

    if (buff == NULL)
        return NULL;

    if ((list = wbxml_list_create()) == NULL)
        return NULL;

    p = buff->data;
    i = 0;
    while (TRUE)
    {
        while (i < buff->len && isspace(*p)) {
            ++p;
            ++i;
        }
        start = i;

        while (i < buff->len && !isspace(*p)) {
            ++p;
            ++i;
        }
        end = i;

        if (start == end)
            break;

        if((word = wbxml_buffer_create(buff->data + start, end - start, WBXML_BUFFER_SPLIT_BLOCK)) == NULL) {
            wbxml_list_destroy(list, wbxml_buffer_destroy_item);
            return NULL;
        }

        wbxml_list_append(list, word);
    }

    return list;
}
示例#4
0
WBXML_DECLARE(WBXMLList*) wbxml_tree_node_get_all_children(WBXMLTreeNode *node)
{
    WBXMLList* result = NULL;
    
    if ( node == NULL )
        return NULL;
    
    node = node->children;
    
    while ( node != NULL ) {
        /* Create result list if not already done */
        if ( result == NULL )
            result = wbxml_list_create();
        
        /* Append node to result */
        wbxml_list_append(result, node);
        
        /* Go to next node */
        node = node->next;
    } 
    
    return result;
}