📄 wbxml_tree.c
字号:
* * <Replace> * <CmdID>162</CmdID> * <Item> * <Source> * <LocURI>./690</LocURI> * </Source> * <Data>EF;CELL:0661809055 * TEL;HOME:0299783886 * X-IRMC-LUID:690 * END:VCARD</Data> * </Item> * </Replace> * * There is no <Meta> info to find the content-type of the <Data>. */ if ( (node->parent != NULL) && (node->parent->parent != NULL) && (node->parent->parent->name != NULL) && ((WBXML_STRCMP(wbxml_tag_get_xml_name(node->parent->parent->name), "Add") == 0) || (WBXML_STRCMP(wbxml_tag_get_xml_name(node->parent->parent->name), "Replace") == 0)) ) { return WBXML_SYNCML_DATA_TYPE_VOBJECT; } } return WBXML_SYNCML_DATA_TYPE_NORMAL;}#endif /* WBXML_SUPPORT_SYNCML */WBXML_DECLARE(WB_BOOL) wbxml_tree_node_have_child_elt(WBXMLTreeNode *node){ WBXMLTreeNode *current = NULL; if (node != NULL) { /* Get first child */ current = node->children; while (current != NULL) { if (current->type == WBXML_TREE_ELEMENT_NODE) { /* Element Node found ! */ return TRUE; } /* Check next child */ current = current->next; } } return FALSE;}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;}WBXML_DECLARE(WBXMLTree *) wbxml_tree_create(WBXMLLanguage lang, WBXMLCharsetMIBEnum orig_charset){ WBXMLTree *result = NULL; if ((result = (WBXMLTree *) wbxml_malloc(sizeof(WBXMLTree))) == NULL) return NULL; result->lang = wbxml_tables_get_table(lang); result->root = NULL; result->orig_charset = orig_charset; return result;}WBXML_DECLARE(void) wbxml_tree_destroy(WBXMLTree *tree){ if (tree != NULL) { /* Destroy root node and all its children */ wbxml_tree_node_destroy_all(tree->root); /* Free tree */ wbxml_free(tree); }}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WB_BOOL) wbxml_tree_add_node(WBXMLTree *tree, WBXMLTreeNode *parent, WBXMLTreeNode *node){ WBXMLTreeNode *tmp = NULL; if ((tree == NULL) || (node == NULL)) return FALSE; /* Set parent to new node */ node->parent = parent; /* Check if this is the Root Element */ if (parent != NULL) { /* This is not the Root Element... search for previous sibbling element */ if (parent->children != NULL) { /* Add this Node to end of Sibbling Node list of Parent */ tmp = parent->children; while (tmp->next != NULL) tmp = tmp->next; node->prev = tmp; tmp->next = node; } else { /* No previous sibbling element */ parent->children = node; } } else { /* We do NOT allow replacement of an existing Tree Node */ if (tree->root != NULL) return FALSE; /* This is the Root Element */ tree->root = node; } return TRUE;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLError) wbxml_tree_extract_node(WBXMLTree *tree, WBXMLTreeNode *node){ if ((tree == NULL) || (node == NULL)) return WBXML_ERROR_BAD_PARAMETER; /* Parent link */ if (node->parent != NULL) { if (node->parent->children == node) { /* Update parent children */ node->parent->children = node->next; } /* No more parent */ node->parent = NULL; } else { /* Root removed ! */ tree->root = node->next; } /* Next link */ if (node->next != NULL) { /* Link next node to previous node */ node->next->prev = node->prev; node->next = NULL; } /* Previous link */ if (node->prev != NULL) { /* Link previous node to next node */ node->prev->next = node->next; node->prev = NULL; } return WBXML_OK;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_elt(WBXMLTree *tree, WBXMLTreeNode *parent, WBXMLTag *tag){ WBXMLTreeNode *node = NULL; /* Create a new Node */ if ((node = wbxml_tree_node_create(WBXML_TREE_ELEMENT_NODE)) == NULL) { return NULL; } /* Set Element */ if ((node->name = wbxml_tag_duplicate(tag)) == NULL) { wbxml_tree_node_destroy(node); return NULL; } /* Add this Node to Tree */ if (!wbxml_tree_add_node(tree, parent, node)) { wbxml_tree_node_destroy(node); return NULL; } return node;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_elt_with_attrs(WBXMLTree *tree, WBXMLTreeNode *parent, WBXMLTag *tag, WBXMLAttribute **attrs){ WBXMLTreeNode *node = NULL; /* Add element */ if ((node = wbxml_tree_add_elt(tree, parent, tag)) == NULL) { return NULL; } /* Add attributes to element */ if ((attrs != NULL) && (*attrs != NULL)) { if (wbxml_tree_node_add_attrs(node, attrs) != WBXML_OK) { /* Remove node from Tree */ wbxml_tree_extract_node(tree, node); wbxml_tree_node_destroy(node); return NULL; } } return node;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_xml_elt(WBXMLTree *tree, WBXMLTreeNode *parent, WB_UTINY *name){ const WBXMLTagEntry *tag_entry = NULL; WBXMLTreeNode *node = NULL; WBXMLTag *tag = NULL; /* Search for XML Tag Name in Table */ if ((tag_entry = wbxml_tables_get_tag_from_xml(tree->lang, (const WB_UTINY *) name)) != NULL) { /* Found : token tag */ tag = wbxml_tag_create_token(tag_entry); } else { /* Not found : literal tag */ tag = wbxml_tag_create_literal(name); } if (tag == NULL) return NULL; /* Create a new Node */ if ((node = wbxml_tree_node_create(WBXML_TREE_ELEMENT_NODE)) == NULL) { wbxml_tag_destroy(tag); return NULL; } /* Set Node Tag */ node->name = tag; /* Add this Node to Tree */ if (!wbxml_tree_add_node(tree, parent, node)) { wbxml_tree_node_destroy(node); return NULL; } return node;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_xml_elt_with_attrs(WBXMLTree *tree, WBXMLTreeNode *parent, WB_UTINY *name, const WB_UTINY **attrs){ WBXMLTreeNode *node = NULL; /* Add element */ if ((node = wbxml_tree_add_xml_elt(tree, parent, name)) == NULL) { return NULL; } /* Add attributes to element */ if ((attrs != NULL) && (*attrs != NULL)) { if (wbxml_tree_node_add_xml_attrs(tree->lang, node, attrs) != WBXML_OK) { /* Remove node from Tree */ wbxml_tree_extract_node(tree, node); wbxml_tree_node_destroy(node); return NULL; } } return node;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_text(WBXMLTree *tree, WBXMLTreeNode *parent, const WB_UTINY *text, WB_ULONG len){ WBXMLTreeNode *node = NULL; /* Create a new Node */ if ((node = wbxml_tree_node_create(WBXML_TREE_TEXT_NODE)) == NULL) { return NULL; } /* Set Content */ if ((node->content = wbxml_buffer_create(text, len, len)) == NULL) { wbxml_tree_node_destroy(node); return NULL; } /* Add this Node to Tree */ if (!wbxml_tree_add_node(tree, parent, node)) { wbxml_tree_node_destroy(node); return NULL; } return node;}/** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_cdata(WBXMLTree *tree, WBXMLTreeNode *parent){ WBXMLTreeNode *node = NULL; /* Create a new Node */ if ((node = wbxml_tree_node_create(WBXML_TREE_CDATA_NODE)) == NULL) { return NULL; } /* Add this Node to Tree */ if (!wbxml_tree_add_node(tree, parent, node)) { wbxml_tree_node_destroy(node); return NULL; } return node;}/** @todo wbxml_tree_add_cdata_with_text() *//** @todo Rewrite this function (use wbxml_tree_node_* functions) */WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_add_tree(WBXMLTree *tree, WBXMLTreeNode *parent, WBXMLTree *new_tree){ WBXMLTreeNode *node = NULL; /* Create a new Node */ if ((node = wbxml_tree_node_create(WBXML_TREE_TREE_NODE)) == NULL) { return NULL; } /* Add this Node to Tree */ if (!wbxml_tree_add_node(tree, parent, node)) { wbxml_tree_node_destroy(node); return NULL; } /* Set Tree */ node->tree = new_tree; return node;}/** @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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -