Monday, August 4, 2014

Debatching -OR- Splitting XML Files using Envelope Schema

Envelope Schema is a special type of schema used in BizTalk Server that is used to represent more than one XML messages embedded in it.

You can use Envelope schema to Split up a Batch XML into individual Files or Split up an XML file that has more that one Embedded XML files into individual Files. 

Here we will see how to split up a Batch XML into Individual XML files:

E.g.: Input – Batch XML File

<Items>
<Item>
<ID>1</ID>
</Item>
<Item>
<ID>2</ID>
</Item>
</Items>
Output  – two Individual XML Files
<Item>
<ID>1</ID>
</Item>
and
<Item>
<ID>2</ID>
</Item>

Below is the sample of split up an XML file that has more than one Embedded XML files into individual Files:

E.g.: Input – Has two types of XML Files

<Items>
<Item1>
<ID1>1</ID1>
</Item1>
<Item2>
<ID2>2</ID2>
</Item2>
</Items>
Output – Two separate xml files

<Item1>
<ID1>1</ID1>
</Item1>
and
<Item2>
<ID2>2</ID2>
</Item2>

Solution:

1. Create a new BizTalk Server Project and two Schemas – Schema1 & Schema2 as shown below :

2. Create a new Schema Schema3 and rename the Root Node to Envelope or some thing else. Add new "any element"

3. Scheme and Go to Properties and make Envelope property to Yes



4. Now select the Root Node Envelope and Go to Properties. Click on the Ellipses next to Body XPath and Select the Root Node itself. ( Here you are specifying that the Body of the Envelope starts with the Root Node itself)

5. Deploy the Application

6. Create One File Receive Port and 2 File Send Ports. Use XML Receive pipeline for Receive Port and pass through pipeline for the send ports.

7. Since we are not using any orchestrations for receiving/routing the separated individual XML files, we have to set the Filter properties of Both the send ports to Subscribe for the individual XML files as given below.

For Send Port1 –  BTS.MessageType == http://BizTalk_Server_Project2.Schema1#Root1

For Send Port2 –  BTS.MessageType == http://BizTalk_Server_Project2.Schema2#Root2

Note: Change the Values according to your project, schema and Root Names. It should be in the format TargetNamespace+#+RootName

Create an Envelope XML file which has Embedded XML files of Schema1 & Schema2:

<ns0:Envelope xmlns:ns0=”http://BizTalk_Server_Project2.Schema3“>
<ns1:Root1 xmlns:ns1=”http://BizTalk_Server_Project2.Schema1“>
<Field1>Field1_0</Field1>
</ns1:Root1>
<ns2:Root2 xmlns:ns2=”http://BizTalk_Server_Project2.Schema2“>
<Field2>Field2_0</Field2>
</ns2:Root2>
</ns0:Envelope>

Drop the above XML in the Receive Folder. Very soon it will be split up into 2 separate XML Files

<ns1:Root1 xmlns:ns1=”http://BizTalk_Server_Project2.Schema1“>
<Field1>Field1_0</Field1>
</ns1:Root1>

and

<ns2:Root2 xmlns:ns2=”http://BizTalk_Server_Project2.Schema2“>
<Field2>Field2_0</Field2>
</ns2:Root2>

These two will be stored in the two folders specified in the Send Ports.

No comments: