Community articleGetLiteralByRefEx 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 finds a particular IFormNodeP on the basis of a reference string. The node you call this function on is used as the starting point for the search unless you provide an absolute reference. Once the IFormNodeP is found, its literal is retrieved.
Note: It is not necessary to call this function when you are using XForms. The UpdateXFormsInstance and ExtractXFormsInstance functions perform this task automatically.

Function

   Function GetLiteralByRefEx(
      theScheme As String,
      theReference As String,
      theReferenceCode As Long,
      theCharSet As String,
      theNSNode As IFormNodeP
      ) As String


Parameters

Table 1. Function parameters
ExpressionTypeDescription
theSchemeStringReserved. This must be null.
theReferenceStringThe reference string.
theReferenceCodeLongReserved. This must be 0.
theCharSetStringThe character set you want to use to view the literal string. Use null for ANSI/Unicode. Use Symbol for Symbol.
theNSNodeIFormNodePA node that is used to resolve the namespaces in theReference parameter (see the note about namespace). Use null if the node that this function is operating on has inherited the necessary namespaces.


Returns

The literal string or throws an exception if an error occurs. If the literal is empty or does not exist, the function returns null.

Usage details

IFormNodeP
Before you decide which IFormNodeP to call the function on, be sure you understand the following:
  1. The IFormNodeP 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 IFormNodeP can be no higher in the hierarchy than an item.
  2. If the IFormNodeP 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 IFormNodeP 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 IFormNodeP and the reference string), the function will fail.
  3. For example, given a IFormNodeP 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.
  4. If the IFormNodeP 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.
Creating a reference string:
For more information about creating a reference, see About references API 801 COMCreate New Article .
Determining namespace:
In some cases, you may want to use the GetLiteralByRefEx function to get the literal of 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>This is Field 1</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:
   Label1Node.GetLiteralByRefEx(vbNullString, "FIELD1.processing:myValue",
      0, vbNullString, vbNullString)

In this example, the GetLiteralByRefEx 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:
   Label1Node.GetLiteralByRefEx(vbNullString, "FIELD1.processing:myValue",
      0, vbNullString, Field1Node)


Example

The following example adds a label to a form. A node is passed into the function, which then uses GetLiteralByRefEx to read the value of a field. The function then uses DereferenceEx to locate the field node, and creates a label node as a sibling using Create. Finally, the function creates a value for the new label node using SetLiteralByRef.
   Sub AddLabel(Form)
 
      Dim TempNode, XFDL ' objects
      Dim Name ' strings
      Set TempNode = Form
 
      ' Get the value of the NameField.value option node
 
      Name = TempNode.GetLiteralByRefEx(vbNullString, _
         "PAGE1.NameField.value", 0, vbNullString, Nothing)
 
      ' Locate the NameField item node in the first page of the form
 
      Set TempNode = TempNode.DereferenceEx(vbNullString, _
      "PAGE1.NameField", 0, UFL_ITEM_REFERENCE, Nothing)
 
      ' Get an XFDL object
 
      Set XFDL = CreateObject("PureEdge.xfdl_XFDL")
 
      ' Create a label.  This label is created as a sibling of the NameField,
      ' and is named NameLabel.
 
      Set TempNode = XFDL.Create(TempNode, UFL_AFTER_SIBLING, "label", _
         vbNullString, vbNullString, "NameLabel")
 
      ' Create a value option for the label.  This option is assigned the
      ' value of Name (as read from the field)
 
      TempNode.SetLiteralByRefEx vbNullString, "value", 0, vbNullString, _
         Nothing, Name
 
   End Sub


Parent topic:
FormNodeP functions