Community articleUFLAddNamespace 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 adds a namespace declaration to the node it is passed. Each namespace is defined in the form using the XML xmlns namespace declaration as shown in these two sample declarations:
   xmlns:xfdl="http://www.ibm.com/xmlns/prod/XFDL/7.7" 
   xmlns:custom="http://www.ibm.com/xmlns/prod/XFDL/Custom"

Each namespace declaration defines a prefix and a URI for the namespace. In the samples shown, the prefix for the XFDL namespace is xfdl and the URI is http://www.ibm.com/xmlns/prod/XFDL/7.7. The prefix for the custom namespace is custom and the URI is http://www.ibm.com/xmlns/prod/XFDL/Custom.
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>


Function

   r_error UFLAddNamespace(
      formNodeP theNode,
      r_charP theURI,
      r_charP thePrefix
   );


Parameters

Table 1. Function parameters
ExpressionTypeDescription
theNode formNodePAny node in the form.
theURIr_charPThe namespace URI. For example:
http://www.ibm.com/xmlns/prod/XFDL/7.7

thePrefixr_charPThe prefix for the namespace. For example, xfdl.


Returns

OK on success or an error code on failure.

Example

The following function uses UFLAddNamespace to add a custom namespace to a form. It then locates the global item in the global page and adds a custom option to that item which marks the status of the form as "Processed".
   r_error addStatus(formNodeP theForm)
   {
   XFDL theXFDL;
   formNodeP tempNode;
   r_error error;
 
      /* Add the custom namespace to the form. */
 
      if ((error = UFLAddNamespace(theForm, 
         "http://www.ibm.com/xmlns/prod/XFDL/Custom", "custom")) != OK)
      {
         fprintf(stderr, "Could not create custom namespace.\n");
         return(error);
      }
 
      /* Locate the global item in the global page so we can add a global
         option. */
 
      if ((tempNode = UFLDereferenceEx(theForm, NULL, "global.global", 0,
         UFL_ITEM_REFERENCE, NULL)) == NULL)
      {
         fprintf(stderr, "Could not locate global item node.\n");
         return(NOTOK);
      }
 
      /* Create a new option node as a child of the global item.  This node
         is created in the custom namespace, called "Status", and given a
         value of "Processed". */
 
      if ((tempNode = UFLCreate(tempNode, UFL_APPEND_CHILD, NULL,
         "Processed", NULL, "custom:Status") == NULL)
      {
         fprintf(stderr, "Could not create option node.\n");
         return(NOTOK);
      }
      return(OK);
   }


Parent topic:
FormNodeP functions