Community articleaddNamespace method
Added by IBM contributorIBM on May 2, 2012
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.



Description

This method adds a namespace declaration to the node it is called on. Each namespace is defined in the form using the XML xmlns namespace declaration as shown in these two sample declarations:
   xmlns:xfdl="http://www.ibm.com/xmlns/prod/XFDL/7.7" 
   xmlns:custom="http://www.ibm.com/xmlns/prod/XFDL/Custom"

Each namespace declaration defines a prefix and a URI for the namespace. In the samples shown, the prefix for the XFDL namespace is xfdl and the URI is http://www.ibm.com/xmlns/prod/XFDL/7.7. The prefix for the custom namespace is custom and the URI is http://www.ibm.com/xmlns/prod/XFDL/Custom.
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">
      <custom:custom_option>value</custom:custom_option>
   </field>


Method

   public void addNamespace(
      String theURI,
      String thePrefix
   ) throws UWIException;


Parameters

Table 1. Method parameters
ExpressionTypeDescription
theURIStringThe namespace URI. For example:
http://www.ibm.com/xmlns/prod/XFDL/7.7

thePrefixStringThe prefix for the namespace. For example, xfdl.


Returns

Nothing or throws a generic exception (UWIException) if an error occurs.

Example

The following method uses addNamespace to add a custom namespace to a form. It then locates the global item in the global page and adds a custom option to that item which marks the status of the form as "Processed".
   private static void addStatus(FormNodeP theNode) throws Exception
   {
   XFDL theXFDL;
 
      /* Add the custom namespace to the form. */
 
      theNode.addNamespace("http://www.ibm.com/xmlns/prod/XFDL/Custom", "custom");
 
      /* Locate the global item in the global page so we can add a global
         option. */
 
      if (theNode = theNode.dereferenceEx(null, "global.global", 0,
         UFL_ITEM_REFERENCE, null) == null)
         throw new UWIException("Could not locate global.global node.");
 
      /* Get the XFDL object so we can create a new node. */
 
      if (theXFDL = (XFDL)IFXMan.lookupInterface(XFDL.XFDL_INTERFACE_NAME,
         XFDL.XFDL_CURRENT_VERSION, 0, null, null)) == null)
         throw new UWIException("Could not find XFDL interface.";
 
      /* Create a new option node as a child of the global item.  This node
         is created in the custom namespace, called "Status", and given a
         value of "Processed". */
 
      if (theNode = theXFDL.create(theNode, UFL_APPEND_CHILD, null,
         "Processed", null, "custom:Status") == null)
         throw new UWIException("Could not create Status node.");
   }


Parent topic:
FormNodeP class