Community articleGetNamespaceURIFromPrefix 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 returns the namespace URI that corresponds to a specific prefix. You can call this function from any node in the form, as long as that node either declares or inherits the namespace in question.
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

   Function GetNamespaceURIFromPrefix(
      thePrefix As String
      ) As String


Parameters

Table 1. Function parameters
ExpressionTypeDescription
thePrefixStringThe namespace prefix. For example, xfdl.


Returns

The namespace URI or throws an exception if an error occurs. If the namespace URI is not declared, the result is null.

Example

The following function copies an option in the custom namespace from one form to another. First, it uses GetNamespaceURIFromPrefix to get the URI for the custom namespace from Form1, then uses AddNamespace to add that namespace to Form2. Next, it uses DereferenceEx to locate the custom node in Form1 and the global page's global item in Form2. Finally, it uses Duplicate to copy the custom node from Form1 into Form2, creating it as a child of the global item.
   Sub CopyCustomInfo(Form1, Form2)
      
      Dim TheURI  ' String
      Dim TempNode, DuplicateNode, GlobalNode  ' IFormNodeP
 
      ' Get the URI for the custom namespace in Form1.
 
      TheURI = Form1.GetNamespaceURIFromPrefix("custom")
 
      ' Create the custom namespace in Form2 using the URI from Form1.
 
      Form2.AddNamespace TheURI, "custom"
 
      ' Locate the custom processing node in Form1.
 
      Set TempNode = Form1.DereferenceEx(vbNullString, _
         "global.global.custom:processing", 0, UFL_OPTION_REFERENCE, _
         Nothing)
 
      ' Locate the global item in Form2
 
      Set GlobalNode = Form2.DereferenceEx(vbNullString, "global.global", _
         0, UFL_ITEM_REFERENCE, Nothing)
 
      ' Copy the custom node from Form1 and insert it as the child of the
      ' global item in Form2.
 
      Set DuplicateNode = TempNode.duplicate(GlobalNode, _
         UFL_APPEND_CHILD, vbNullString)
 
   End Sub


Parent topic:
FormNodeP functions