Description This function finds a particular formNodeP on the basis of a reference string. You must provide a node that is used as the starting point for the search unless you provide an absolute reference. Once the formNodeP is found, its literal is retrieved.
Note: It is not necessary to call this function when you are using XForms. The UFLUpdateXFormsInstance and UFLExtractXFormsInstance functions perform this task automatically.
Table 1. Function parameters
|aNode ||formNodeP||A formNodeP that determines which form to search, and provides a starting point for the search if an absolute reference is not provided.|
|theScheme||r_charP||Reserved. This must be NULL.|
|theReference||r_charP||The reference string.|
|theReferenceCode||r_short||Reserved. This must be 0.|
|theCharSet||r_charP||The character set you want to use to view the literal string. Use NULL or ANSI for ANSI. Use Symbol for Symbol.|
|theNSNode||formNodeP||A node that is used to resolve the namespaces in theReference parameter (see the note about namespace below). Use NULL if the node that this function is operating on has inherited the necessary namespaces.|
|theLiteralPtr ||r_charP*||A pointer to the literal string. If the literal is empty or does not exist, the string is set to NULL. This string must be freed by the caller.|
Returns OK on success or an error code on failure.
Before you decide which formNodeP to use as the aNode parameter, be sure you understand the following:
Creating a reference string:
For more information about creating a reference, see About references .
In some cases, you may want to use the UFLGetLiteralByRefEx function to get the literal of a node that does not have a globally defined namespace. For example, consider the following form:
- The formNodeP supplied can never be more than one level in the hierarchy above the starting point of the reference string. For example, if the reference string begins with an option, then the formNodeP can be no higher in the hierarchy than an item.
- 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.
- If the formNodeP is at the argument level, the search will not start from that point. Instead, the nearest ancestor that is at the option level will be used as the starting point for the search.
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:
<field sid="FIELD1" xmlns:processing="URI">
<value>This is Field 1</value>
In this example, the UFLGetLiteralByRefEx function fails. 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 LABEL1) as a parameter in the function:
error = UFLGetLiteralByRefEx(Label1Node, NULL,
"FIELD1.processing:myValue", 0, NULL, NULL, &theLiteral)
error = UFLGetLiteralByRefEx(Label1Node, NULL,
"FIELD1.processing:myValue", 0, NULL, Field1Node, &theLiteral)
Example The following example uses UFLGetLiteralByRefEx to get the literal value from a specific node. That value is then converted into an integer.
r_error getCurrentDate(formNodeP form, int *curMonth, int *curDay)
error = UFLGetLiteralByRefEx(form, NULL, PAGE1.CURRENTMONTH.value",
0, NULL, NULL, &temp);
if (error != OK)
fprintf(stderr, "UFLGetLiteralByRefEx error %hd.\n", error);
/* If a literal value was returned, convert it into an integer value;
otherwise, indicate that no value was entered into the field and throw
an exception. */
if (temp != NULL)
*curMonth = atoi((char *)temp);
fprintf(stderr, "The current month was not entered.\n");
/* additional code removed */
/* Free memory */
temp = NULL;