Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
26 May 2005 1  
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