Building the XMLNSC Namespaces sample

You can use the instructions in this topic to build the XMLNSC Namespaces sample. Alternatively, you can import the completed message set and Integration project for the sample. You must import the XMLNSC Namespaces sample files into your workspace before you use the instructions to build the sample.

To build the XMLNSC Namespaces sample:

  1. Create a message set called XMLNSCnamespaceMS. The message set uses the XMLNSC runtime parser.
    1. Open the New Message Set wizard. To do this, right-click anywhere in the Application Development view, then click New > Independent Resources > Message Set.
    2. Set XMLNSCnamespaceMS as the Message set name.
    3. Click Finish.
    4. Ensure that the default message domain is set to XMLNSC.
    5. Close the message set.
  2. Import XML schema files into the XMLNSCnamespaceMS message set. The XML Schema files contain definitions for the SaleListMessage message that is used in many of the IBM Integration Bus samples.
    1. In the Application Development view, expand the CHANGENAMESPACEMS message set project.
    2. Select the following files:
      • SampleMessage.xsd
      • SampleMessageNamespace1.xsd
      • SampleMessageNamespace2.xsd
    3. Right-click the selected files and click Copy.
    4. Right-click the XMLNSCnamespaceMS message set project and click Paste. The XML Schema files are added to the XMLNSCnamespaceMS message set.
  3. Create message definition files from the XML schema files.
    1. Right-click SampleMessage.xsd in the XMLNSCnamespaceMS message set project and click New > Message Definition File From > XML Schema File.
    2. Ensure that SampleMessage.xsd is selected in the New Message Definition File wizard and click Next.
    3. Click Finish.
    4. Repeat these steps to create message definition files from the remaining XML Schema files: SampleMessageNamespace1.xsd and SampleMessageNamespace2.xsd.
  4. Create the XMLNSCnamespaceMF Integration Broker project.
  5. Create the ADDNAMESPACEMF message flow. This message flow accepts an input message from an MQInput node by using the XMLNSC parser. The input message, called SalesListMessage, uses namespaces. The message flow adds a namespace to the message and outputs the updated message from an MQOutput node.
    1. Right-click the XMLNSCnamespaceMF Integration project and click New > Message Flow.
    2. Set Message Flow name to ADDNAMESPACEMF and click Finish.
    3. Add the following nodes to the message flow canvas:
      • 1 MQInput node
      • 1 Compute node
      • 1 MQOutput node
    4. Connect the Out terminal of the MQInput node to the In terminal of the Compute node.
    5. Connect the Out terminal of the Compute node to the In terminal of the MQOutput node.
    6. Configure the node properties as shown in the following table.

      Node Page Property Value
      MQInput Basic Queue name ADDNAMESPACEMF.IN
      Input Message Parsing Message domain XMLNSC
      Validation Validate Inherit
      Compute Validation Validate Inherit
      MQOutput Basic Queue name

      ADDNAMESPACEMF.OUT


    7. Right-click the Compute node and click Open ESQL.
    8. Add the following ESQL code to the top of the ESQL file, before the ADDNAMESPACEMF_Compute module. The ChangeNamespaceInOutputRoot and ChangeNamespace ESQL functions are used by all the message flows in the sample.
      CREATE FUNCTION ChangeNamespaceInOutputRoot(In rootNode REFERENCE, In oldNamespace CHARACTER, In newNamespace CHARACTER)
      BEGIN
      	--
      	-- Need to remove schemalocation and namespace declarations
      	--
      	IF newNamespace = '' THEN
      		SET rootNode.(XMLNSC.Element)*[1].*:schemaLocation = NULL;
      		DECLARE I1 INTEGER CARDINALITY(rootNode.(XMLNSC.Element)*[1].(XMLNSC.NamespaceDecl)*[]);
      		DECLARE I2 INTEGER 1;
      		WHILE I2 <= I1 DO
      			SET rootNode.(XMLNSC.Element)*[1].(XMLNSC.NamespaceDecl)*[1] = NULL;
      			SET I2 = I2 + 1;
      		END WHILE;	 
      	ELSE
      	--
      	-- Need to modify the schema locations and the namespace declarations
      	--
      	-- The target schemalocations can be identified within the source message's
      	-- MQRFH2 header, <usr> folder, tag <TargetSchemaLocation>
      	--
      		IF rootNode.(XMLNSC.Element)*[1].*:schemaLocation IS NOT NULL THEN
      			SET rootNode.(XMLNSC.Element)*[1].*:schemaLocation = newNamespace;
      		END IF;	
      	END IF;	
      	--		
      	-- CHECKSIBLING is a flag which, when set to TRUE, ensures that the WHILE loop does an
      	-- unconditional MOVE ... NEXTSIBLING (rather than MOVE ... FIRSTCHILD)
      	-- We need this when we go up a level in the tree... otherwise we go back where we have
      	-- just come from
      	--
      	DECLARE CHECKSIBLING BOOLEAN FALSE;
      	--
      	-- DEPTH determines when to finish.  
      	-- Every time we MOVE FIRSTCHILD we add 1 to DEPTH
      	-- Every time we MOVE PARENT we subtract 1 from DEPTH
      	-- MOVE NEXTSIBLING does not change DEPTH
      	-- Initial value is 1, so we are finished when DEPTH = 0
      	--
      	DECLARE DEPTH INTEGER 1;
      	--
      	-- Walk the tree top to bottom, left to right
      	--
      	WHILE DEPTH <> 0 DO 
      		IF CHECKSIBLING = FALSE THEN 
      			MOVE rootNode FirstChild;
      		 	IF LASTMOVE(rootNode) = TRUE THEN
      				SET DEPTH = DEPTH + 1;
      				CALL ChangeNamespace(rootNode, oldNamespace, newNamespace);
      		 	ELSE
      		 		MOVE rootNode NEXTSIBLING;
      			 	IF LASTMOVE(rootNode) = TRUE THEN
      					CALL ChangeNamespace(rootNode, oldNamespace, newNamespace);
      					SET CHECKSIBLING = FALSE;
      			 	ELSE
      					SET DEPTH = DEPTH - 1;
      					Move rootNode PARENT;		 		
      					SET CHECKSIBLING = TRUE;
      				END IF;
      		 	END IF;	
      		ELSE
      			MOVE rootNode NEXTSIBLING;
      		 	IF LASTMOVE(rootNode) = TRUE THEN
      				CALL ChangeNamespace(rootNode, oldNamespace, newNamespace);
      				SET CHECKSIBLING = FALSE;
      		 	ELSE
      				SET DEPTH = DEPTH - 1;
      				Move rootNode PARENT;		 		
      				SET CHECKSIBLING = TRUE;
      			END IF;
      		END IF;
      	END WHILE;
      END;
      
      CREATE FUNCTION ChangeNamespace(IN rootNode REFERENCE, In oldNamespace CHARACTER, In newNamespace CHARACTER)
      BEGIN
      	--
      	-- Check for elements/attributes with the source namespace		
      	--
          IF (FIELDTYPE(rootNode) = Name) OR (FIELDTYPE(rootNode) = NameValue) THEN
      		IF FIELDNAMESPACE(rootNode) IN (oldNamespace) THEN 
      			--
      			-- Set the new target namespace
      			--
      			SET rootNode NAMESPACE = newNamespace;
      			--
      			-- Get rid of any inline namespace definitions
      			--
      			SET rootNode.(XMLNSC.NamespaceDecl)* = NULL;
      		END IF;
          END IF;
      END;
      
    9. Code the following ESQL for the Main module:
      CREATE COMPUTE MODULE ADDNAMESPACEMF_Compute
      
      	CREATE FUNCTION Main() RETURNS BOOLEAN
      	BEGIN
      		DECLARE SourceNamespace NAMESPACE '';
      		DECLARE TargetNamespace NAMESPACE 'http://www.samplemessage.brokertest.hursley.ibm.com';
      
      		CALL CopyMessageHeaders();
      
      		DECLARE oldNamespace CHARACTER '';
      		DECLARE newNamespace CHARACTER '';
      		
      		SET oldNamespace = SourceNamespace;
      		SET newNamespace = TargetNamespace;
      		
      		IF InputRoot.MQRFH2.usr.SourceNamespace IS NOT NULL THEN
      			SET oldNamespace = InputRoot.MQRFH2.usr.SourceNamespace;
      		END IF;	
      		-- The target namespace can be specified dynamically in the MQRFH2 header.  
      		-- The following logic checks whether the MQRFH2 contains this info;  if it does not, 
      		-- defaults are supplied in the message flow. 
      				
      		IF InputRoot.MQRFH2.usr.TargetNamespace IS NOT NULL THEN
      			SET newNamespace = InputRoot.MQRFH2.usr.TargetNamespace;
      		ELSE	
      			SET newNamespace = TargetNamespace;
      		END IF;	
      				
      		-- Make the output tree the same as the input tree.  
      		SET OutputRoot.XMLNSC = InputBody;
      		
      		-- Change the namespace of the root element.
      		DECLARE rootNode REFERENCE TO OutputRoot.XMLNSC.*[<];
      		CALL ChangeNamespace (rootNode, oldNamespace, newNamespace);
      		
      		-- Alternatively, apply namespaces to local (nested) elements too.
      		-- DECLARE rootNode REFERENCE TO OutputRoot.XMLNSC;
      		-- CALL ChangeNamespace (rootNode, oldNamespace, newNamespace);
      		
      		RETURN TRUE;
      	END;
      
      	CREATE PROCEDURE CopyMessageHeaders()
      	BEGIN
      		DECLARE I INTEGER 1;
      		DECLARE J INTEGER;
      		SET J = CARDINALITY(InputRoot.*[]);
      		WHILE I < J DO
      			SET OutputRoot.*[I] = InputRoot.*[I];
      			SET I = I + 1;
      		END WHILE;
      	END;
      	
      	CREATE PROCEDURE CopyEntireMessage() BEGIN
      		SET OutputRoot = InputRoot;
      	END;
      
      END MODULE;
      
    10. Save ADDNAMESPACEMF.esql and ADDNAMESPACEMF.msgflow.
  6. Create the CHANGENAMESPACEMF message flow. This message flow accepts an input message from an MQInput node by using the XMLNSC parser. The input message, called SalesListMessage, uses namespaces. The message flow changes the namespace that is used by the message and outputs the updated message from an MQOutput node.
    1. Right-click the XMLNSCnamespaceMF Integration project and click New > Message Flow.
    2. Set Message Flow name to CHANGENAMESPACEMF and click Finish.
    3. Add the following nodes to the message flow canvas:
      • 1 MQInput node
      • 1 Compute node
      • 1 MQOutput node
    4. Connect the Out terminal of the MQInput node to the In terminal of the Compute node.
    5. Connect the Out terminal of the Compute node to the In terminal of the MQOutput node.
    6. Configure the node properties as shown in the following table.

      Node Page Property Value
      MQInput Basic Queue name CHANGENAMESPACEMF.IN
      Input Message Parsing Message domain XMLNSC
      Validation Validate Content and Value
      Compute Validation Validate Inherit
      MQOutput Basic Queue name

      CHANGENAMESPACEMF.OUT


    7. Right-click the Compute node and click Open ESQL.
    8. Replace the ESQL in the CHANGENAMESPACEMF_Compute module with the following code:
      CREATE COMPUTE MODULE CHANGENAMESPACEMF_Compute
      	CREATE FUNCTION Main() RETURNS BOOLEAN
      	BEGIN
      		DECLARE SourceNamespace NAMESPACE 'http://www.samplemessage.broker.hursley.ibm.com';
      		DECLARE TargetNamespace NAMESPACE 'http://www.samplemessage.brokertest.hursley.ibm.com';
      
      		CALL CopyMessageHeaders();
      
      		DECLARE oldNamespace CHARACTER '';
      		DECLARE newNamespace CHARACTER '';
      		
      		SET oldNamespace = SourceNamespace;
      		SET newNamespace = TargetNamespace;
      
      		IF InputRoot.MQRFH2.usr.SourceNamespace IS NOT NULL THEN
      			IF InputRoot.MQRFH2.usr.SourceNamespace = 'NONAMESPACE' THEN
      				SET oldNamespace = '';
      			ELSE	
      				SET oldNamespace = InputRoot.MQRFH2.usr.SourceNamespace;
      			END IF;
      		ELSE	
      			SET oldNamespace = SourceNamespace;
      		END IF;	
      
      		-- The target namespace can be specified dynamically in the MQRFH2 header.  
      		-- The following logic checks whether the MQRFH2 contains this info;  if it does not, 
      		-- defaults are supplied in the message flow. 
      				
      		IF InputRoot.MQRFH2.usr.TargetNamespace IS NOT NULL THEN
      			IF InputRoot.MQRFH2.usr.TargetNamespace = 'NONAMESPACE' THEN
      				SET newNamespace = '';
      			ELSE	
      				SET newNamespace = InputRoot.MQRFH2.usr.TargetNamespace;
      			END IF;
      		ELSE	
      			SET newNamespace = TargetNamespace;
      		END IF;	
      	
      		-- Make the output tree the same as the input tree.  
      		-- We will then walk the tree changing things as we go   
      
      		SET OutputRoot.XMLNSC = InputBody;
      		DECLARE rootNode REFERENCE TO OutputRoot.XMLNSC;
      		CALL ChangeNamespaceInOutputRoot (rootNode, oldNamespace, newNamespace);
      		RETURN TRUE;
      	END;
      
      	CREATE PROCEDURE CopyMessageHeaders()
      	BEGIN
      		DECLARE I INTEGER 1;
      		DECLARE J INTEGER;
      		SET J = CARDINALITY(InputRoot.*[]);
      		WHILE I < J DO
      			SET OutputRoot.*[I] = InputRoot.*[I];
      			SET I = I + 1;
      		END WHILE;
      	END;
      
      	CREATE PROCEDURE CopyEntireMessage()
      	BEGIN
      		SET OutputRoot = InputRoot;
      	END;
      	
      END MODULE;
      
    9. Save CHANGENAMESPACEMF.esql and CHANGENAMESPACEMF.msgflow.
  7. Create the DELETENAMESPACEMF message flow. This message flow accepts an input message from an MQInput node by using the XMLNSC parser. The input message, called SalesListMessage, uses namespaces. The message flow deletes the namespace used by the message and outputs the updated message from an MQOutput node.
    1. Right-click the XMLNSCnamespaceMF Message Broker project and click New > Message Flow.
    2. Set Message Flow name to DELETENAMESPACEMF and click Finish.
    3. Add the following nodes to the message flow canvas:
      • 1 MQInput node
      • 1 Compute node
      • 1 MQOutput node
    4. Connect the Out terminal of the MQInput node to the In terminal of the Compute node.
    5. Connect the Out terminal of the Compute node to the In terminal of the MQOutput node.
    6. Configure the node properties as shown in the following table.

      Node Page Property Value
      MQInput Basic Queue name DELETENAMESPACEMF.IN
      Input Message Parsing Message domain XMLNSC
      Validation Validate Content and Value
      Compute Validation Validate Inherit
      MQOutput Basic Queue name

      DELETENAMESPACEMF.OUT


    7. Right-click the Compute node and click Open ESQL.
    8. Add the the following ESQL between BEGIN and END for the DELETENAMESPACEMF_Compute module to call the ChangeNamespaceInOutputRoot function:
      CREATE COMPUTE MODULE DELETENAMESPACEMF_Compute
      	CREATE FUNCTION Main() RETURNS BOOLEAN
      	BEGIN
      		DECLARE SourceNamespace NAMESPACE 'http://www.samplemessage.broker.hursley.ibm.com';
      		DECLARE TargetNamespace NAMESPACE '';
      		
      		CALL CopyMessageHeaders();
      		
      		DECLARE oldNamespace CHARACTER '';
      		DECLARE newNamespace CHARACTER '';
      		
      		SET oldNamespace = SourceNamespace;
      		SET newNamespace = TargetNamespace;
      
      		-- The target namespace can be specified dynamically in the MQRFH2 header.  
      		-- The following logic checks whether the MQRFH2 contains this info;  if it does not, 
      		-- defaults are supplied in the message flow. 
      				
      		IF InputRoot.MQRFH2.usr.SourceNamespace IS NOT NULL THEN
      			IF InputRoot.MQRFH2.usr.SourceNamespace = 'NONAMESPACE' THEN
      				SET oldNamespace = '';
      			ELSE	
      				SET oldNamespace = InputRoot.MQRFH2.usr.SourceNamespace;
      			END IF;
      		ELSE	
      			SET oldNamespace = SourceNamespace;
      		END IF;	
      				
      		-- Make the output tree the same as the input tree.  
      		-- We will then walk the tree changing things as we go   
      		SET OutputRoot.XMLNSC = InputBody;
      		DECLARE rootNode REFERENCE TO OutputRoot.XMLNSC;
      		CALL ChangeNamespaceInOutputRoot (rootNode, oldNamespace, newNamespace);
      		RETURN TRUE;
      	END;
      
      
      	CREATE PROCEDURE CopyMessageHeaders()
      	BEGIN
      		DECLARE I INTEGER 1;
      		DECLARE J INTEGER;
      		SET J = CARDINALITY(InputRoot.*[]);
      		WHILE I < J DO
      			SET OutputRoot.*[I] = InputRoot.*[I];
      			SET I = I + 1;
      		END WHILE;
      	END;
      	
      	CREATE PROCEDURE CopyEntireMessage() BEGIN
      		SET OutputRoot = InputRoot;
      	END;
      
      END MODULE;
    9. Save DELETENAMESPACEMF.esql and DELETENAMESPACEMF.msgflow.
  8. Deploy the Integration project XMLNSCnamespaceMF to an integration node.
    1. Right-click Broker Archives and click New > Message Broker Archive.
    2. Select a Server project and set the File Name for the broker archive to XMLNSCnamespace.bar.
    3. Click Finish.
    4. Add Integration project XMLNSCnamespaceMF to XMLNSCnamespace.bar
    5. Save the broker archive file.
    6. Deploy the XMLNSCnamespace.bar to an integration node.

Back to sample home