Community articleUFLDuplicate function
Added by IBM contributorIBM on July 26, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Description

This function makes a copy of a node. The duplicated node can be attached to any other node as either a sibling or a child, or can be stored as a separate node structure. The new node can also be assigned a new identifier with the theIdentifier parameter. All of the properties of the original node are duplicated, including any children and any namespace settings.
Note: If you duplicate a node that is not in the XFDL namespace, the namespace is copied as part of the duplicated node, but is not set globally.

Function

   formNodeP UFLDuplicate(
      formNodeP origNode,
      formNodeP baseNode,
      r_short where,
      r_charP theIdentifier
   );


Parameters

Table 1. Function parameters
ExpressionTypeDescription
origNode formNodePThe formNodeP to copy.
baseNodeformNodePThe formNodeP to attach the new copy to. If NULL, then origNode is used as the baseNode.
where r_shortA constant that describes the location in relation to the supplied baseNode in which the new node should be placed. Can be one of:
UFL_APPEND_CHILD — adds the new node as the last child of the baseNode.
UFL_AFTER_SIBLING — adds the new node as a sibling of the baseNode, placing it immediately after that node in the form structure.
UFL_BEFORE_SIBLING — adds the new node as a sibling of the baseNode, placing it immediately before that node in the form structure.
UFL_ORPHAN — copies the node but does not insert it into the form structure.
theIdentifierr_charPThe new id attribute for this node. If NULL, the id attribute of the original node is used.


Returns

The duplicate node on success or NULL on failure.

Example

In the following example, UFLDereferenceEx is used to locate a specific node. UFLDuplicate is then used to duplicate that node. Finally, UFLSetLiteralByRefEx is used to change the literal of the duplicate "value" node.
   r_error createMailing(formNodeP form) 
   { 
   formNodeP tempNode;
   r_error error;
 
      if ((tempNode = UFLDereferenceEx(form, NULL, 
         "PAGE1.ADDRESSFIELD", 0, UFL_ITEM_REFERENCE, NULL)) == NULL) 
      { 
         fprintf(stderr, "Could not locate the ADDRESSFIELD node.\n");
         return(NOTOK); 
      } 
      if ((tempNode = UFLDuplicate(tempNode, NULL, UFL_AFTER_SIBLING,                                        
         "MAILINGFIELD")) == NULL) 
      { 
         fprintf(stderr, "Could not duplicate ADDRESSFIELD.\n"); 
         return(NOTOK); 
      }
 
      error = UFLSetLiteralByRefEx(form, NULL, PAGE1.MAILINGFIELD.label", 
         0, NULL, NULL, (r_charP)"Mailing Address:");
      if (error != OK) 
      { 
         fprintf(stderr, "UFLSetLiteralByRefEx error %hd.\n", error);
         return(NOTOK); 
      } 
      return(OK); 
   }


Parent topic:
FormNodeP functions