Debatching(Splitting) XML Message - BizTalk 2010

Amazon Free Music
{tocify} $title={Table of Contents}


Introduction


In this post we will walk through the process of debatching xml message using Biztalk.


Scenario


We receive many item information but its wrapped(Enveloped) , so to process each item we need to unwrap it ( remove envelope and split individual Item message.

Below is what we receive(Input) :
<ns0:Items xmlns:ns0="http://TestingSchemas.ItemEnvelope">
  <ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_0</ID> 
  <Name>Name_0</Name> 
  <Quantity>100</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
  <ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_0</ID> 
  <Name>Name_1</Name> 
  <Quantity>200</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
  <ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_2</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_3</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_4</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_5</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_6</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_7</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_8</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
<ns1:Product xmlns:ns1="http://TestingSchemas.Item">
  <ID>ID_9</ID> 
  <Name>Name_2</Name> 
  <Quantity>300</Quantity> 
  <UnitPrice>100</UnitPrice> 
  </ns1:Product>
  </ns0:Items>



But we want(Output) :




      <ns0:Product xmlns:ns0="http://TestingSchemas.Item">
           <ID>ID_0</ID>
          <Name>Name_0</Name>
          <Quantity>100</Quantity>
          <UnitPrice>100</UnitPrice>
      </ns0:Product>
             .
             .
             .
             .
             .

     <ns0:Product xmlns:ns0="http://TestingSchemas.Item">
        <ID>ID_9</ID>
        <Name>Name_9</Name>
        <Quantity>100</Quantity>
        <UnitPrice>100</UnitPrice>
     </ns0:Product>


  Allright , lets see how we do it:


Steps in creating solution


 1. Create schema - document schema 
create  document schema

2. Create the wrapper - Envelope Schema
  • Name the root node, I have named it Items.


Envelope Schema




  • Click on "Schema" and go to Properties Window
  • Set the property "Envelope" as Yes , as this schema will be used as envelope and this is the property which helps disassembler to recognize it.
  • So far good , envelope schema is ready but what about the document which will be wrapped.
Envelope Schema with document schema specified
  • In the Property window select "Imports" and click on the ellipsis 
  • You will get Imports wizard pop-ed  out  .
  • Click on add and select the document schema which we created in step 1.(Here it is Item schema)

Add document schema

  • Click on the "Items" and go to property window and select the property Body XPath and set it to /*[local-name()='Items' and namespace-uri()='http://TestingSchemas.ItemEnvelope']. Doing so allows Items node to contain any number of Item Document.
  • Cool... now we are ready with the resources, next is to validate schema ,build it, sign it  and deploy.


set body xpath

3. Now create a Receive port which will receive enveloped message(ItemEnvelope Type) .
  •            Select XMLReceive pipeline
xmlreceive pipeline

4.Now create a Send port which will send individual xml message (Item Type)
  •          Select XMLTransmit pipeline
  •          Add Filter (this creates subcription ) : BTS.ReceivePortName == ReceiveItem
  •         After splitting the message , the pipeline would submit individual Item Messages and as we are creating subscription , all the messages submitted by ReceiveItem port will be picked by SendPort
Add filter on port

5. Now lets test, I will drop a envelope message at receive location which we saw at start  . So I should be getting 10 individual xml message at the destination location:
testing
6.Did we really got the messages split-ted:

splitted messages


Will keep on posting as an when I find something to share!!!!!!!!!!!!


 If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!



Amazon Free Music

Related Post 


1 Comments

If you have any suggestions or questions or want to share something then please drop a comment

  1. Sorry for replying on the old thread , but did you change the "Data Structure Type" when you finished the Import step on step 2?

    ReplyDelete
Previous Post Next Post