Community articleUFLGetNamespaceURI function
Added by IBM contributorIBM on August 16, 2011
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.



Description

This function returns the namespace URI 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 was in the custom namespace you would use the prefix custom as shown:
   <field sid="testField">
      <custom:custom_option>value</custom:custom_option>
   </field>


Function

   r_error UFLGetNamespaceURI(
      formNodeP theFormNode,
      r_charP *theURI
   );


Parameters

Table 1. Function parameters
ExpressionTypeDescription
theFormNodeformNodePThe formNodeP to retrieve the namespace URI for.
theURIr_charP*A pointer to the URI. This string must be freed by the caller.


Returns

OK on success or an error code on failure.

Example

The following function uses recursion to traverse the entire node structure and destroys all nodes that are in the custom namespace identified by the following URI: http://www.ibm.com/xmlns/prod/XFDL/Custom. This function assumes that you are passing in the root node of the form.
   r_error deleteCustomInfo(formNodeP theNode)
   {
   formNodeP tempNode, tempNode2;
   r_charP theURI;
 
      /* Use recursion to step through each node of the form. */
 
      if ((tempNode = UFLGetChildren(theNode)) == NULL)
      {
         fprintf(stderr, "Could not locate child node.");
         return(NOTOK);
      }
      while(tempNode != null)
      {
         if ((tempNode2 = UFLGetNext(tempNode)) == NULL)
         {
            fprintf(stderr, "Could not locate sibling.");
            return(NOTOK);
         }
         if ((error = deleteCustomInfo(tempNode)) != OK)
         {
            fprintf(stderr, "deleteCustomInfo returned an error.");
            return(NOTOK);
         }
         tempNode = tempNode2;
      }
      
      /* Get the namespace URI for the node. */
 
      if ((UFLGetNamespaceURI(theNode, &theURI)) != OK)
      {
         fprintf(stderr, "Could not get namespace URI.");
         return(NOTOK);
      }
 
      /* If the node belongs to the custom namespace, delete it. */
 
      if (cp_strcmp(theURI, "http://www.ibm.com/xmlns/prod/XFDL/Custom") == OK)
      {
         if (UFLDestroy(theNode) != OK)
         {
            fprintf(stderr, "Could not delete node.");
            return(NOTOK);
         }
      }
 
      /* Free memory. */
 
      cp_free(theURI);
      return(OK);
   }


Parent topic:
FormNodeP functions