Community articleUFLGetPrefixFromNamespaceURI 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 a specific namespace URI.
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">


   r_error UFLGetPrefixFromNamespaceURI(
      formNodeP theFormNode,
      r_charP theURI,
      r_charP *thePrefix


Table 1. Function parameters
theFormNode formNodePAny node in the form that either declares or inherits the namespace in question.
theURIr_charPThe namespace URI. For example:

thePrefix r_charP*A pointer that will contain the prefix. If the namespace URI is not declared, the pointer is set to NULL.
Note that this string must be freed by the caller.


OK on success or an error code on failure.


The following function adds custom information to a form and assumes that the namespace URI for the custom information is known but that the prefix used to represent that namespace in the form is not known. First, the function uses UFLGetPrefixFromNamespaceURI to get the prefix in use. The function then concatenates the prefix with the name for the new node, "Status". Finally, the function locates the global item in the global page and creates a new option node.
   r_error addStatus(formNodeP theNode)
   r_charP thePrefix;
   r_charP theNodeName;
      /* Get the prefix for the custom namespace. */
      if ((UFLGetPrefixFromNamespaceURI(theNode, 
         "", &thePrefix)) != OK)
         fprintf(stderr, "Could not get namespace prefix.");
      /* Check whether the prefix is NULL. */
      if (thePrefix == NULL)
         fprintf(stderr, "The namespace URI does not exist.");
      /* Allocate memory to hold a name for the new node. */
      theNodeName=cp_malloc(cp_strlen(thePrefix) + 8);
      /* Create a name for a new node by concatenating the prefix with 
         "Status". */
      cp_strcpy(theNodeName, thePrefix);
      cp_strcat(theNodeName, ":Status");
      /* Locate the global item in the global page so we can add a global 
         option. */
      if ((theNode = UFLDereferenceEx(theNode, NULL, "", 0,
         fprintf(stderr, "Could not find node.");
      /* Create a new node in the custom namespace and give it a value 
         of "Processed". */
      if ((theNode = UFLCreate(theNode, UFL_APPEND_CHILD, NULL,
         "Processed", NULL, theNodeName)) == NULL)
         fprintf(stderr, "Could not create node.");
      /* Free memory. */

Parent topic:
FormNodeP functions