Community articlegetNamespaceURIFromPrefix method
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 method returns the namespace URI that corresponds to a specific prefix. You can call this method 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:

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
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">


   public String getNamespaceURIFromPrefix(
      String thePrefix
  ) throws UWIException;


Table 1. Method parameters
thePrefixStringThe namespace prefix. For example, xfdl.


The namespace URI or throws a generic exception (UWIException) if an error occurs. If the namespace URI is not declared, the result is null.


The following method copies a custom option from one form to another. The method assumes that you know the prefix for the custom namespace, but not the URI. First, the method uses getNamespaceURIFromPrefix to get the URI for the custom namespace in the first form. Next, it adds that namespace to the second form as a globally available namespace. It then locates the custom node in the first form and the global item node in the second form. Finally, it copies the custom node to the second form as a child of the global item node.
   private static void copyCustomInfo(FormNodeP form1, FormNodeP form2) 
      throws Exception
      String theURI;
      FormNodeP tempNode, duplicateNode, globalNode;
      /* Get the URI for the custom namespace in form 1. If the URI is null, 
         throw an error. */
      if ((theURI = form1.getNamespaceURIFromPrefix("custom")) == null)
         throw new UWIException("Custom namespace not declared in form.");
      /* Create a custom namespace in form 2 using that URI. */
      form2.addNamespace(theURI, "custom");
      /* Locate the custom Status node in form 1. */
      if ((tempNode = form1.dereferenceEx(null, 
         "", 0, UFL_OPTION_REFERENCE | 
         UFL_SEARCH, null)) == null)
         throw new UWIException("Could not find custom Status node.");
      /* Locate the global item in form 2. */
      if ((globalNode = form2.dereferenceEx(null, "", 0,
         UFL_ITEM_REFERENCE | UFL_SEARCH, null)) == null)
         throw new UWIException("Could not locate global item.");
      /* Copy the custom node from form 1 and insert it as a child of 
         the global item in form 2. */
      if ((duplicateNode = tempNode.duplicate(globalNode, UFL_APPEND_CHILD,
         null)) == null)
         throw new UWIException("Could not duplicate node.");

Parent topic:
FormNodeP class