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

Description

This function returns the namespace prefix for the node.
Each namespace is defined in the form by a namespace declaration, as shown:
   xmlns:xfdl="http://www.ibm.com/xmlns/prod/XFDL/7.5" 
   xmlns:custom="http://www.ibm.com/xmlns/prod/XFDL/Custom"

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 http://www.ibm.com/xmlns/prod/XFDL/7.5.
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">
      <custom:custom_option>value</custom:custom_option>
   </field>


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.

Function

   r_error UFLGetPrefix(
      formNodeP theFormNode,
      r_charP *thePrefix
   );


Parameters

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


Returns

OK on success or an error code on failure.

Example

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.");
            return(NOTOK);
         }
         tempNode = tempNode2;
      }
      
      /* Get the namespace prefix for the node. */
 
      if (UFLGetPrefix(theNode, &thePrefix) != OK)
      {
         fprintf(stderr, "Could not get namespace URI.");
         return(NOTOK);
      }
 
      /* 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.");
            return(NOTOK);
         }
      }
 
      /* Free memory. */
 
      cp_free(thePrefix);
 
      return(OK);
   }


Parent topic:
FormNodeP functions