Community articleUFLSetLiteralByRefEx function
Added by IBM contributorIBM on May 2, 2012
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 finds a particular formNodeP as specified by a reference string. Once the formNodeP is found, its literal will be set as specified. If the formNodeP does not exist, this function will create it, but only if the formNodeP would be an option or argument node.
If necessary, this function can create several nodes at once. For example, if you set the literal for the second argument of an itemlocation, this function will create the itemlocation option node and the two argument nodes and then set the literal for the second argument node.
This function cannot create a formNodeP at the form, page, or item level; to do so, use UFLCreate.
Note: It is not necessary to call this function when you are using XForms. Use the UFLUpdateXFormsInstance function instead.

Function

   r_short UFLSetLiteralByRefEx(
      formNodeP aNode,
      r_charP theScheme,
      r_charP theReference,
      r_short theReferenceCode,
      r_charP theCharSet,
      formNodeP theNSNode,
      r_charP theLiteral
   );


Parameters

Table 1. Function parameters
ExpressionTypeDescription
aNode formNodePA formNodeP to use as a starting point for the search (unless an absolute reference is used).
theSchemer_charPReserved. This must be NULL.
theReferencer_charPA string that contains the reference.
theReferenceCoder_shortReserved. Must be 0.
theCharSetr_charPThe character set in which theLiteral parameter is written. Use NULL or ANSI for ANSI. Use Symbol for Symbol.
theNSNodeformNodePA node that is used to resolve the namespaces in theReference parameter (see “Determining Namespace” in the Notes® section below). Use NULL if the node that you are calling this function on has inherited the necessary namespaces.
theLiteralr_charPThe string that will be assigned to the literal. If NULL, any existing literal is removed.


Returns

OK on success or an error code on failure.

Usage details

FormNodeP:
Before you decide which formNodeP to use this function on, be sure you understand the following:
  1. The formNodeP you supply can never be more than one level in the hierarchy above the level at which your reference string starts. For example, if the reference string begins with an option, then the formNodeP can be no higher in the hierarchy than an item.
  2. If the formNodeP is at the same level or lower in the hierarchy than the starting point of the reference string, the function will attempt to locate a common ancestor. The function will locate the ancestor of the formNodeP that is one level in the hierarchy above the starting point of the reference string. The function will then attempt to follow the reference string back down through the hierarchy. If the reference string cannot be followed from the located ancestor (for example, if the ancestor is not common to both the formNodeP and the reference string), the function will fail. For example, given a formNodeP that represents "field_1" and a reference of "field_2", the function will access the "page" node above "field_1", and will then try to locate "field_2" below that node. If the two fields are not on the same page, the function will fail.
Creating a reference string:
For more information about creating a reference, see About references.
Digital signatures:
Do not set a node that is digitally signed. Doing so will break the digital signature and produce an error.
Determining namespace:
In some cases, you may want to use the UFLSetLiteralByRefEx function to set the value for a node that does not have a globally defined namespace. For example, consider the following form:
   <label sid="Label1">
      <value>Field1.processing:myValue</value>
   </label>
   <field sid="Field1" xmlns:processing="URI">
      <value></value>
      <processing:myValue>10<processing:myValue>
   </field>

In this form, the processing namespace is declared in the Field1 node. Any elements within Field1 will understand that namespace; however, elements outside of the scope of Field1 will not.
In cases like this, you will often start your search at a node that does not understand the namespace of the node you are trying to locate. For example, you might want to locate the node referenced in the value of Label1. In this case, you would first locate the Label1 value node and get its literal. Then, from the Label1 value node, you would attempt to locate the processing:myValue node as shown:
   error = UFLSetLiteralByRefEx(Label1Node, NULL,
      "Field1.processing:myValue", 0, NULL, NULL, "20")

In this example, the UFLSetLiteralByRefEx function would fail. The function cannot properly resolve the processing namespace because this namespace is not defined for the Label1 value node. To correct this, you must also provide a node that understands the processing namespace (in this case, any node in the scope of Field1) as a parameter in the function:
   error = UFLSetLiteralByRefEx(Label1Node, NULL,
      "Field1.processing:myValue", 0, NULL, Field1Node, "20")


Example

In the original form, the label for the Age field instructs the user to leave the field blank. However, now that the field has been filled in by a formula, this label needs to be changed. In the following example UFLSetLiteralByRefEx is used to change this value.
   r_error setFormula(formNodeP form, int curMonth, int curDay,
   int birMonth, int birDay)
   {
   formNodeP tempNode=NULL;
   r_error error=OK;
 
      /* Additional code removed */
 
      error = UFLSetLiteralByRefEx(form, NULL, "PAGE1.AGELABEL.value", 0,
         NULL, NULL, "Age:");
      if (error != OK)
      {
         fprintf(stderr, "UFLSetLiteralByRefEx error %hd.\n", error);
         return(NOTOK);
      }
      return(OK);
   }


Parent topic:
FormNodeP functions