Sunday, 28 June 2015

Split XML repeating child Node along with its common fields and create separate message in Biztalk Orchestration.

Hi all,

I got a requirement where I have to split a incoming xml message into individual message based on number of child nodes. Ok no need to confuse I will tell Step by Step with snapshot:

This is my Input message:


As you can see that we have child node  <TESTSTATUS_DETAIL> which has been repeating two times in this message. This can repeat n number of times.

What I want to do here that I want To Extract every child node one by one in orchestration wanted to create single separate message for each child node. For example in this message child node has been repeated two times so we will create two individual message along with its common fields.

The ouput I want like below snapshot:



this is first single message in which first child node has been selected. second message will also be of same structure but the second child node will be selected and so on third , fourth if any.

To achieve this target in orchestration I have done some steps; First I will show u complete orchestration and then step by step process:

This is my complete orchestration snapshot:








Now shape By shape details:

Shape 1 (Msg Receive Shape:)

In this I am receiving my Input message which I have shown u in above pic.


Shape 2(JobCount Expression Shape)

XmlCompleteContent = msg_Test ;

ElementCount=1;


CountVar=(System.Int32)xpath(msg_Test, "count(/*[local-name()='TEST_EVENTS' and namespace-uri()='http://TEST.BizTalk.Schemas.XML_Target_JobEvents']/*[local-name()='TESTSTATUS_DETAIL' and namespace-uri()=''])");


I have written this code in this shape. Here I have taken XmlCompleteContent as variable of type xml. Since I need to loop it through so I am initialising ElementCount=1; and using Xpath I am couting the no of child nodes in CountVar which is type of int variable.

Shape 3(Loop Shape)

In this shape I have written ElementCount<=CountVar as we do in any loop 

Shape 4(Construct Message Shape)

msg_Test=XmlCompleteContent;

XpathStatement= System.String.Format("//*[local-name()='TEST_EVENTS' and namespace-uri()='http://TEST.BizTalk.Schemas.XML_Target_JobEvents']/*[local-name()='TESTSTATUS_DETAIL' and namespace-uri()='']["+ ElementCount.ToString() +"]");
xmlContent = xpath(msg_Test, XpathStatement);


In this shape we are constructing the Msg_Test message is of type Xml Target Schema.

Below is the snapshot of Xml_Target Schema.


Within Construct message shape in second message assignment Shape we are creating our support schema which will extract the child node and assign to message Msg_orchestration Support. This message is of type Support Schema.  Below is the snapshot of Support Schema.




we have writteb the below code in 2nd message assignment shape:

varXML = new System.Xml.XmlDocument();

varXML.LoadXml(@"<TESTSTATUS_DETAIL>
  <EMPID>EMPID_0</EMPID>
  <CMP>CMP_0</CMP>
  <CCD>CCD_0</CCD>
  <KDTLCTN>KDTLCTN_0</KDTLCTN>
  <KDTUTC>KDTUTC_0</KDTUTC>
  <DNM>DNM_0</DNM>
  <KOFF>KOFF_0</KOFF>
  <LCD>LCD_0</LCD>
  <LOFF>LOFF_0</LOFF>
  <TLCTN>TLCTN_0</TLCTN>
  <TUTC>TUTC_0</TUTC>
</TESTSTATUS_DETAIL>");


msgOrchestrationSupport = varXML;

msgOrchestrationSupport=xmlContent;

Shape 5(Construct Message Shape)

In this shape we are constructing the message_test01 message which is also type of Xml Target Schema.

For achieving this we are using transformation.
Below is the Snapshot of transformation:




Shape 5(Expression_increment Shape)

In this shape I have written below Code:



ElementCount= ElementCount + 1;


                                                            Thank you for reading this post. If any errror is there please give me feedback so that I can improve. Happy Coding



No comments:

Post a Comment