Community articlegetPrefixFromNamespaceURI method
Added by IBM contributorIBM on August 15, 2011
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.


This method returns the namespace prefix for a specific namespace URI. 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 is in the custom namespace, use the prefix custom as shown:
   <field sid="testField">


   public String getPrefixFromNamespaceURI(
      String theURI
   ) throws UWIException;


Table 1. Method parameters
theURIStringThe namespace URI. For example:


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


The following method adds custom information to a form and assumes that the namespace URI for the custom information is known but that the prefix used to represent that namespace in the form is not known. First, the method uses getPrefixFromNamespaceURI to get the prefix in use. The method then concatenates the prefix with the name for the new node, "Status". Finally, the method locates the global item in the global page and creates a new option node.
   private static void addStatus(FormNodeP theNode) throws Exception
   XFDL theXFDL;
   String thePrefix;
   String theNodeName;
      /* Retrieve the prefix for the custom namespace. If the prefix is
         null, throw an error. */
      if ((thePrefix = theNode.getPrefixFromNamespaceURI(
         "")) == null)
         throw new UWIException("Custom namespace not declared in form.");
      /* Create a name for a new node by concatenating the prefix with 
         "Status". */
      theNodeName = thePrefix + ":Status";
      /* Locate the global item in the global page so we can add a global
         option. */
      if (theNode = theNode.dereferenceEx(null, "", 0,
         UFL_ITEM_REFERENCE | UFL_SEARCH, null) == null)
         throw new UWIException("Could not locate node.");
      /* Get the XFDL object so we can create a new node. */
      if ((theXFDL = IFSSingleton.getXFDL()) == null)
         throw new UWIException("Could not find XFDL interface.");
      /* Create a new node in the custom namespace and give it a value 
         of "Processed". */
      if (theNode = theXFDL.create(theNode, UFL_APPEND_CHILD, null,
         "Processed", null, theNodeName) == null)
         throw new UWIException("Could not create Status node.");

Parent topic:
FormNodeP class