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

It’s a little disappointment but the documentation in the RTM version of BizTalk 2004 is quite limited. There will be an updated set of docs available in late March/early April but that’s not a solution for now. Therefore I’m posting my early experiences with this product: no rocket science but basic things I struggled with a little bit. The first example is how to split a large XML message into parts, so each part can be processed separately.

Image you have following message that contains information about one or more customers; the Customers node can contain any number Customer nodes.
<Customers>
    <Customer>
        <CustomerID>1</CustomerID>
        <Name>Customer One</Name>
    </Customer>
    <Customer>
        <CustomerID>2</CustomerID>
        <Name>Customer Two</Name>
    </Customer>
</Customers>
Suppose you don’t want to process all the customer’s at once, but you want to be able to process each Customer node one by one in your orchestration. This can be done by using a Envelope schema and a Document schema: the envelope (Customers node) contains any number of documents (Customer node). So let’s create these schema’s in BizTalk:

  1. Start a new empty BizTalk project and add a new schema, name it for example CustomerDocument.
  2. Change the name of the Root node to something more descriptive like “Customer”.
  3. Add the “CustomerID” and “Name” properties as Child Field Elements to the schema.
  4. That’s it for the Document schema, so let’s add a new schema to the project and name it “CustomersEnvelope”.
  5. Identify the new schema as an envelope  by selecting the Schema node and change the Envelope property to Yes in the Properties window.
  6. Change the name of the Root node to “Customers”.
  7. 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 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 want to use an XSD Import, you can set the Data Structure Property to “xs:anyType”.
  8. 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']

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 for example.
  2. Add a 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.

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

  1. Add a new orchestration to the project.
  2. Add a port to the orchestration that will receive the messages.
  3. Set the Receive Pipeline property of that port to CustomersReceivePipeline (the one that we’ve created above).
  4. Now you can add a Receive shape to the orchestration that receives a message of the CustomerDocument shema type.

Next you’ll need to add your logic to the orchestration. As a result of the receive pipeline, the Customers node will be disassembled into Customer nodes that will be passed into your orchestration as separate messages. I need to thank Christof Claessens for his recommendations. Christof is guy that really knows a lot of BizTalk 2004, I’ve talked to him a couple of times and each time I learn something new, thanks!

14 Comments

  • I face an additional problem. In addition to splitting a message, I want to have envelope fields available in my orchestration, e.g. attribute receiveDate when the envelope contained a root element like &lt;customers receiveDate=&quot;...&quot;&gt;.



    Is this possible?

  • Thanks for this info Jan. I have been trying to do get Biztalk to do this. And your post definately helped. I have an issue though and was wondering if you know what it is..



    I created a sample XML as specified above and passed it through this process. The file is removed from the input, but no output is produced. I changed the test XML file to contain the schema information as below and this processes fine, two messages are produced in my output. Any ideas why I need to have the schemas included?



    &lt;ns0:Customers xmlns:ns0=&quot;http://MultiCustomer.CustomersEnvelope&quot;&gt;

    &lt;ns1:Customer xmlns:ns1=&quot;<a target="_new" href="http://MultiCustomer.CustomerDocument&quot;&gt;">http://MultiCustomer.CustomerDocument&quot;&gt;

    &lt;CustomerID&gt;1&lt;/CustomerID&gt;

    &lt;Name&gt;Customer One&lt;/Name&gt;

    &lt;/ns1:Customer&gt;

    &lt;ns1:Customer xmlns:ns1=&quot;<a target="_new" href="http://MultiCustomer.CustomerDocument&quot;&gt;">http://MultiCustomer.CustomerDocument&quot;&gt;

    &lt;CustomerID&gt;2&lt;/CustomerID&gt;

    &lt;Name&gt;Customer Two&lt;/Name&gt;

    &lt;/ns1:Customer&gt;

    &lt;/ns0:Customers&gt;

  • is it posible to split my output xml file in Send port.

  • Srini, I'm not aware of any methods to do this.

  • Hi

    I am new to Biztalk and would appreciate if any body has the posting on how to create the orchestration of this sample.

    Regards

    Nina

  • I've done all that you've described. However I have this poblem that I am getting one file(exact copy of the input file) as the output. I would like to have two files (two customers)

    as the output.

    The only thing i've done differently is that instead of an orchestration, I've added a send port and subscribed to all messages arriving at the receive location.

  • Encountered same error as Emiel.

  • I had the same failure on the receive pipeline. Undeploying doesn't clean out the GAC as you would expect. I fixed it by incrementing the version of the project and re-deploying.

  • Hi

    Iam trying to add header file to my output given by mapper and attach header file in send pipeline.I have tried with my header schema to give as header file to my output.Thanks

    Ram

  • for your question about spliting flat files into multiple xml docs

    check C:\Program Files\Microsoft BizTalk Server 2004\SDK\Samples\Pipelines\AssemblerDisassembler\EnvelopeProcessing.



    You shall find the anwser you seek.

  • Anyone know what settings I would have to change to go from the following schema:

    &lt;ns0:Customers xmlns:ns0=&quot;http://Test.customersenvelope&quot;&gt;

    &lt;ns1:Customer xmlns:ns1=&quot;<a target="_new" href="http://Test.CustomerDocument&quot;&gt;">http://Test.CustomerDocument&quot;&gt;

    &lt;CustomerID&gt;1&lt;/CustomerID&gt;

    &lt;Name&gt;Customer One&lt;/Name&gt;

    &lt;/ns1:Customer&gt;

    &lt;ns1:Customer xmlns:ns1=&quot;<a target="_new" href="http://Test.CustomerDocument&quot;&gt;">http://Test.CustomerDocument&quot;&gt;

    &lt;CustomerID&gt;2&lt;/CustomerID&gt;

    &lt;Name&gt;Customer Two&lt;/Name&gt;

    &lt;/ns1:Customer&gt;

    &lt;/ns0:Customers&gt;

    To this simpler one:

    &lt;Customers&gt;

    &lt;Customer&gt;

    &lt;CustomerID&gt;1&lt;/CustomerID&gt;

    &lt;Name&gt;Customer One&lt;/Name&gt;

    &lt;/Customer&gt;

    &lt;Customer&gt;

    &lt;CustomerID&gt;2&lt;/CustomerID&gt;

    &lt;Name&gt;Customer Two&lt;/Name&gt;

    &lt;/Customer&gt;

    &lt;/Customers&gt;

    Thanks for the awesome example!

  • Great article.

    How do we do this using .NET component?

  • Great article.
    It's working great on file adapter but not with SOAP...
    any help will be appriciated.
    eladr@tip.co.il

  • Home gift baskets gift basket gift baskets new jersey new grandparents gift baskets corporate gift basket scheduled delivery gift baskets gourmet basket business gift home start gift baskets champagne and chocolate taffy christmas gift basket from north carolina wine gift baskets maryland

Comments have been disabled for this content.