Community articleUFLRemoveAttribute 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 removes a specific attribute from a node. For example, the following XFDL represents a value node:
   <value custom:myAtt="x"></value>

To remove the custom attribute from this node, you would use removeAttribute.


   r_error UFLRemoveAttribute(
     formNodeP theObject,
     r_charP theNamespaceURI,
     r_charP theAttribute


Table 1. Function parameters
theNode formNodePThe node containing the attribute you want to remove.
theNamespaceURIr_charPThe namespace URI for the attribute. For example:

theAttributer_charPThe local name of the attribute. For example, compute, encoding, and so on.


OK on success or an error code on failure.

Usage details

Attributes and the null namespace:
If an attribute is on a node in a non-XFDL namespace, and that attribute has no namespace prefix, then the attribute is in the null namespace. For example, the following node is the custom namespace, as is the first attribute, but since the second attribute does not have a namespace prefix, it is in the null namespace:
   <custom:processing custom:stage="2" user="tjones">

When an attribute is the null namespace, you may either provide a NULL value for the namespace URI or use the namespace URI for the containing element.
For example, to indicate user attribute on the processing node, you could use the null namespace or the custom namespace URI.
Attributes and namespace prefixes:
If you refer to an attribute with a namespace prefix, UFLRemoveAttribute first looks for a complete match, including both prefix and attribute name. If it does not find such a match, it will look for a matching attribute name that has no prefix but whose containing element has the same namespace.
For example, assume that the custom namespace and the test namespace both resolve to the same URI. In the following case, looking for the id attribute would locate the second attribute (test:id), since it has an explicit namespace declaration:
   <a xmlns:custom="ABC" xmlns:test="ABC">
      <custom:myElement id="1" test:id="2">

However, in the next case, the id attribute does not have an explicit namespace declaration. Instead, it inherits the custom namespace. However, since the inherited namespace resolves to the same URI, the id attribute is still located:
   <custom:myElement id="1">


The following function uses UFLDereferenceEx to locate a custom node in the form. It then uses UFLRemoveAttribute to delete the "stage" attribute from the node, and calls UFLSetAttribute to update the value of the status attribute to "completed".
   r_error CompletedProcessing(form)
      formNodeP tempNode;
      /* Locate the custom processing node in the global item */
      if ((tempNode = UFLDereferenceEx(form, NULL,
         "", 0, UFL_OPTION_REFERENCE, NULL))
         == NULL)
         fprintf(stderr, "Could not locate custom node.\n");
      /* Remove the "stage" attribute from the node */
      if (UFLRemoveAttribute(tempNode, NULL, "stage") != OK)
         fprintf(stderr, "Could not remove attribute.\n");
      /* Update the status attribute to "completed" */
      if (UFLSetAttribute(tempNode, NULL, "status", "completed") != OK)
         fprintf(stderr, "Could not remove attribute.\n");

Parent topic:
FormNodeP functions