# # # compare_node_existence.cfv # # subroutine(compare_node_existence( node a_ori, node b_ori), ( debug_message("#### compare_node_existence() \n"); # This subroutine compares two nodes without its values (values are not compared!) and displays any node differences in a HTML table. # The order of the subnodes is not relevant. Nodes which are sorted differently but have # the same subnodes and values will show that the two nodes are equal. # # # # compare_node_existence_a_against_b() # # # subroutine(compare_node_existence_a_against_b( node a, node b, node c), ( node item; string item_value; string item_path; string parent_path; foreach item a ( if (num_subnodes(item) > 0) then ( compare_node_existence_a_against_b(item, b, c); ) else ( item_path = replace_first(item, "v.compare_node_existence_a.", ""); # debug_message("#### item_path in a: " . item_path . "\n"); if (!?(b . "." . item_path)) then ( # Track that the node only exists in a # debug_message("#### TRACK NODE IN C\n\n"); c . "." . item_path . ".__node_exists_in_a__" = true; c . "." . item_path . ".__node_exists_in_b__" = false; ); ); ); )); # # # # compare_node_existence_b_against_a() # # # subroutine(compare_node_existence_b_against_a( node a, node b, node c), ( node item; string item_name; string item_path; foreach item b ( # debug_message("#### item: " . item . "\n"); # debug_message("#### num_subnodes(item): " . num_subnodes(item) . "\n"); if (num_subnodes(item) > 0) then ( compare_node_existence_b_against_a(a, item, c); ) else ( item_path = replace_first(item, "v.compare_node_existence_b.", ""); # debug_message("#### item_path of item in b: " . item_path . "\n"); # If this subnode does not exist in a then add it to c, # else it has already been covered in compare_node_existence_a_against_b if (!?(a . "." . item_path)) then ( c . "." . item_path . ".__node_exists_in_a__" = false; c . "." . item_path . ".__node_exists_in_b__" = true; ); ); ); )); # # # # compare_node_existence_create_node_differences_html() # # # subroutine(compare_node_existence_create_node_differences_html( node c), ( node item; string item_name; string item_path; foreach item c ( if (item?{"__node_exists_in_a__"} and item?{"__node_exists_in_b__"}) then ( item_path = replace_first(item, "v.compare_node_existence_c.", ""); # Show the item ''; # Left item (a) if (@item{"__node_exists_in_a__"}) then ( '' . item_path . ''; # ' = '; # 'values are ignored'; ) else ( '-'; ); # Right item (b) if (@item{"__node_exists_in_b__"}) then ( '' . item_path . ''; # ' = '; # 'values are ignored'; ) else ( '-'; ); ''; ) else ( compare_node_existence_create_node_differences_html(item); ); ); )); delete_node("v.compare_node_existence_a"); delete_node("v.compare_node_existence_b"); delete_node("v.compare_node_existence_c"); v.compare_node_existence_a = ""; v.compare_node_existence_b = ""; v.compare_node_existence_c = ""; # This is the result node to which any differences are written. node a = "v.compare_node_existence_a"; node b = "v.compare_node_existence_b"; node c = "v.compare_node_existence_c"; clone_node(a_ori, a); clone_node(b_ori, b); # debug_message("\n\n" . node_as_string(a) . "\n\n"); # Compare a against b compare_node_existence_a_against_b(a, b, c); # Compare b against a # debug_message("\n\n" . node_as_string(b) . "\n\n"); compare_node_existence_b_against_a(a, b, c); debug_message("#### Node differences:\n\n" . node_as_string(c) . "\n\n"); bool is_node_differences = (num_subnodes(c) > 0); # # # Create final output # # ''; ''; ''; # ''; # ''; ''; # ''; # ''; ''; if (is_node_differences) then ( compare_node_existence_create_node_differences_html(c); ); '
' . a_ori . '  ' . b_ori . '  
'; if (!is_node_differences) then ( '

There are no differences between the above nodes.

'; ); # Clean up delete_node(a); delete_node(b); delete_node(c); ));