Click here to Skip to main content
Click here to Skip to main content
Go to top

How to split an XML message in BizTalk 2004 using Document and Envelope Schemas

, 26 May 2005
Rate this:
Please Sign up or sign in to vote.
This tutorial will show you how to disassamble a batch of multiple records to individual records.

Introduction

In my last project I had a requirement where we will be getting multiple records in a single file, and we have to loop through the file to get a single record and process it. I got a very good article on this written by Jan. Thanks Jan.

When I was trying to implement the tutorial provided by Jan, I faced a few silly problems, obviously because of my lack of knowledge. So, I thought of putting the same, in a more simpler way.

So, we will take the same example to develop our tutorial where we have the customer information containing the CustomerID and Name and this information will come to us as a batch file under customers node.

We will execute the following steps to implement this tutorial:

  1. Create document schema.
  2. Create envelop schema.
  3. Test XML file against schemas.
  4. Create receive pipeline which will bread the batch into individual requests.
  5. Create receive and send port and shape.

Create document schema

  1. Start a new empty BizTalk project and add a new schema, as CustomerDocument.
  2. Change the name of the root node to Customer.
  3. Add the CustomerID and Name properties as the child field elements to the schema.

    Note: Make sure that the schema looks similar to the above image, for me it created problems. The point is to set xs:int and xs:string as “Data Type” property and not “Base Data Type” property.

Create envelop schema

  1. Let’s add a new schema to the project and name it “CustomersEnvelope”.
  2. Identify the new schema as an envelope by selecting the schema node and changing the Envelope property to Yes in the Properties window.
  3. Change the name of the root node to Customers.
  4. You can import the document schema into the envelope schema by clicking on the ellipsis button for the Imports property of the schema node. You’ll get a dialog window in which you can add an “XSD Import” of the CustomerDocument schema. Then add a new child record node under the Customers node and name it Customer. Set the Data Structure property of this new node to “ns0:Customer”. (If you haven’t changed the namespace: If you don’t like ns0 notation, and want to put proper notation, use “ab|” tag provided in the import dialog. See the image shown below for more details.)

    Note: If you don’t want to use an XSD Import, you can set the Data Structure property to “xs:anyType”. When you say “xs:anyType” it will remove the child nodes. That is why, this way is not preferable as it will increase the complexity.

  5. Change to “Body XPath” property of the Customers node by clicking the ellipsis button and point to the Customers node. The property will be set to: /*[local-name()='Customers' and namespace-uri()='http://XMLSplitExample.CustomersEnvelope']

    Note: Make sure that your xPath is exactly similar to the one given above, by default it will append some other code also.

Test XML file against schemas

So now we have created the perfect document as well as the envelop schemas. If you want to make sure before going further you can use the utility called xmldasm.exe which can be found in <sdk>\Utilities\PipelineTools folder. From here you can copy the xmldasm.exe and PipelineObjects.dll files to your working folder and execute the following command at command prompt:

xmldasm batch.xml -ds customerdocument.xsd -es customerenvelope.xsd

If everything is fine, then you will get a separate file for each record given in batch.xml file.

You can also use IDE to generate valid XML file for you from the schema using the following steps:

  1. Right click on customerenvelop.xsd file, go to property and set “Output Instance FileName” to Batch.xml file.
  2. Again right click on customerenvelop.xsd, select Generate Instance from the menu.

Create receive pipeline

Next you need to configure a new ReceivePipeline in which the schemas created above will be used:

  1. Add a new ReceivePipeline to your project and name it CustomerReceivePipeline.
  2. Add an XML disassembler to the disassemble stage of the ReceivePipeline.

  3. Set the Document schemas property of that XML disassembler to the CustomerDocument schema.
  4. Set the Envelope schemas property of the XML disassembler to the CustomersEnvelope schema.

Create receive and send port and shape.

Now the CustomersReceivePipeline can be used in an orchestration; so let’s do that:

  1. Add a new orchestration to the project, name the orchestration as BatchOrc.
  2. Add a port to the orchestration.
  3. Once you add a port to Port Surface Area, it will open the port configuration wizard as shown below:

    Click on Next and provide the port name as ReqPort and click Next which will take you to the following screen:

    Enter the details given above and click Next. This will take you to the following screen where we will configure the pattern of port like, type of port receive or send and specify the listening port, see the screen shown below for more details:

    Note: Note that we have to specify the CustomerReceivePipeline we created above as the receive pipeline.

    In a similar way, we can create the sending port with the direction “I’ll always be sending messag…” and receive pipeline as “XMLTransmit”. Refer to the screen below:

    Note: If you want to send the data to SQL database for insertion then you have to bind the port later. May be I will discuss this in my next tutorial.

  4. Now we will add a receive shape to the orchestration that receives a message of the CustomerDocument schema type.
  5. Similarly we will add send shape to the orchestration that sends a message of the CustomerDocument schema type to send port configured earlier.
  6. Once everything is set, we can compile and deploy the orchestration to the BizTalk server.

Summary

Hope this tutorial will help you to develop your cool orchestration. If you need any further help do mail me at gaurang.desai@gmail.com.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Gaurang Desai
Architect
United States United States
Currently he is working as Senior Soft. Engineer at Cognizant Technology Solution.He is involved in various project activities like System Architecture, Design, and Development. He is fond of conduction training for various technologies. He has have worked on various language and platforms. He is Microsoft and Oracle Certified professional. He is spending quantity and quality time in .Net world. He had also spoiled his hand with java, too.
If work is not demanding, he spends good time with his wife, Purvi.He
blogs
at WebDevs.com.

Comments and Discussions

 
Generaladding NS0: I am get getting error hexadecimal not allowed? PinmemberMyRitu12-Jun-11 11:37 
GeneralGreat...! Thanks Pinmembershaik Ghyasuddin24-May-10 4:04 
Questionneed help with xml split PinmemberEhab M. Saad15-Dec-09 13:43 
QuestionCan this process (spilt an XML Message) work with Child Field Attribute PinmemberBurnett_s26-Nov-09 14:13 
GeneralEnvelope schema with Any Pinmembercramshady30-Mar-09 0:24 
GeneralRe: Envelope schema with Any PinmemberOlivier Delestret19-Nov-09 3:11 
GeneralDeloying without orchestration in BizTalk 2006 Pinmembervraw8-Nov-07 5:11 
GeneralError with Receive Pipeline PinmemberThunderBiz16-Oct-07 10:11 
GeneralRe: Error with Receive Pipeline PinmemberPushkarAditya129-Jan-09 21:49 
GeneralRe: Error with Receive Pipeline Pinmembersanggarra19-Aug-09 4:38 
GeneralError running the sampe project Pinmemberssashok26-May-06 4:41 
AnswerRe: Error running the sampe project PinmemberBruno Spinelli3-Jun-07 15:48 
QuestionBatchProcess? PinmemberNITH3-Jul-05 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 26 May 2005
Article Copyright 2005 by Gaurang Desai
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid