Splitting XML Files using Envelope Schema

Posted: November 23, 2010  |  Categories: Schemas Uncategorized

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. This is show below.

  1. Split up a Batch XML into Individual XML files.

Eg: 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>
  1. Split up an XML file that has more than one Embedded XML files into individual Files

Eg: 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
    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

    1. 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>
    1. 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>
  1. These two will be stored in the two folders specified in the Send Ports

– Shiv

  • pipi

    Very good !

  • Bala

    Hi,
    i am getting the following error while sending the files according to the above scenario. can you please look into it and let me know the resolution please.
    There was a failure executing the receive pipeline: “Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” Source: “XML disassembler” Receive Port: “ReceivePort4” URI: “F:BalaTestsample projectDebatching sampleDebatching sampleIN*.xml” Reason: An error occurred when parsing the incoming document: “There are multiple root elements. Line 2, position 2.”.

    • Your error message gives you the clear description – “There are multiple root elements. Line 2, position 2“..
      So basically your input xml file is not in proper format.. make sure that it has one root node only..

One Platform Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

One Platform - Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

One Platform - Operations, Monitoring and Analytics Software
ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

Back to Top