2.2.3.17.33 TreeNode::Replace

Description

Replaces a node in the tree.

Syntax

BOOL Replace( TreeNode & tn, BOOL bDeep = TRUE, BOOL bKeepTagName = FALSE, BOOL bKeepAttributes = FALSE )

Parameters

tn
[input]the new node to be added to the tree
bDeep
[input] TRUE or FALSE;
bKeepTagName
[input] True if keep tn's tagname.
bKeepAttributes
[input] True will keep all attribute of treenode

Return

TRUE if the node is successfully replaced; FALSE otherwise

Examples

EX1

void TreeNode_Replace_ex1()
{
    Tree tr;
    TreeNode tn1 = tr.AddNumericNode(123, "node1", 1);            
    TreeNode tn2 = tr.AddTextNode("abc", "node2", 2);
    TreeNode tn21 = tn2.AddTextNode("dfg", "node3", 3);
    TreeNode tn211 = tn21.AddNumericNode(456, "node4", 4);
    out_tree(tr);
    /*
					tr
                 /		\
            node1(123)	node2(abc)
							|        
						node3(dfg)  
							|
						node4(456)
    */
	// bDeep is TRUE, tn1 will be replaced by tn3 and its children.
	// bKeepTagName is TRUE, tagname of tn1 will be keep. 
	// bKeepAttributes is FALSE, tn1's ID will be replaced by tn3's.
    bool flag = tn1.Replace(tn21, TRUE, TRUE, FALSE);
    if(flag) 
        printf("node3 successfully replaced \n");
    out_tree(tr); 
    
    int ID;
    if ( tn1.GetAttribute("NodeID", ID) )
        printf("the attribute ID %d", ID);

}

Remark

See Also

Header to Include

origin.h