Community articleUFLGetPrefix 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


This function returns the namespace prefix for the node.
Each namespace is defined in the form by a namespace declaration, as shown:

Each namespace declaration defines both a prefix and a URI for the namespace. In this sample, the prefix for the XFDL namespace is xfdl and the URI is
Tags within the form are assigned specific namespaces by using the defined prefix. For example, to declare that an option is in the custom namespace, use the prefix custom as shown:
   <field sid="testField">

Note: A given prefix may not always resolve to the same namespace. Different portions of the form may define the prefix differently. For example, the custom prefix may resolve to a different namespace on the first page of a form than it does on the following pages.


   r_error UFLGetPrefix(
      formNodeP theFormNode,
      r_charP *thePrefix


Table 1. Function parameters
theFormNodeformNodePThe formNodeP to get the namespace prefix for.
thePrefixr_charP*A pointer to the prefix. This string must be freed by the caller.


OK on success or an error code on failure.


The following function removes all nodes from the form that have a namespace prefix of "custom". The function walks through the form using UFLGetChildren and UFLGetNext in a recursive loop. While walking the form, it uses UFLGetPrefix to locate nodes in the custom namespace and deletes them using UFLDestroy. This function assumes that you are passing it the root node of the form.
   r_error deleteCustomInfo(formNodeP theNode)
   formNodeP tempNode, tempNode2;
   r_charP thePrefix;
      /* Use recursion to step through each node of the form. */
      tempNode = UFLGetChildren(theNode);
      while(tempNode != null)
         tempNode2 = UFLGetNext(tempNode);
         if (deleteCustomInfo(tempNode) != OK)
            fprintf(stderr, "deleteCustomInfo returned an error.");
         tempNode = tempNode2;
      /* Get the namespace prefix for the node. */
      if (UFLGetPrefix(theNode, &thePrefix) != OK)
         fprintf(stderr, "Could not get namespace URI.");
      /* If the node belongs to the custom namespace, delete it. */
      if (cp_strcmp(thePrefix, "custom") == 0)
         if (UFLDestroy(theNode) != OK)
            fprintf(stderr, "Could not delete node.");
      /* Free memory. */

Parent topic:
FormNodeP functions