![]() |
Enterprise Systems »
Microsoft BizTalk Server »
General
Intermediate
How to split an XML message in BizTalk 2004 using Document and Envelope SchemasBy Gaurang DesaiThis tutorial will show you how to disassamble a batch of multiple records to individual records. |
C#, XML, Windows, .NET 1.1VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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:
Customer.
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.
Envelope property to Yes in the Properties window.
Customers.
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.
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.
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:


Next you need to configure a new ReceivePipeline in which the schemas created above will be used:
ReceivePipeline to your project and name it CustomerReceivePipeline.
ReceivePipeline.

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

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.

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.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 26 May 2005 Editor: Chris Maunder |
Copyright 2005 by Gaurang Desai Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |