Message Debatching inside Biztalk Orchestration, with TargetNamespace

|  Posted: December 18, 2006  |  Categories: BizTalk Server
You can download the entire article as a PDF document.
Message Debatching inside Biztalk Orchestration, with TargetNamespace

Recently I end up in a scenario where I need to debatch a message inside the orchestration to produce multiple messages based on XPATH. There are already quite few articles about it, one good one is from Stephen Thomas hands on lab.

Only problem with this lab is, the examples are based on schemas without any TargetNamespace. In a real world situation its hard to imagine a schema without a TargetNamespace, so I spend some time to enhance the sample with TargetNamespace. I’ll highlight some of the things you need to take care when using schemas with TargetNamespace.

Download: The attached zip file contains the complete BizTalk Solution. follow the steps below to configure it:

1. Extract the sample BizTalkDebatching to C:BTSSamples

2. Open the project in visual studio, build and deploy it. (Don’t need to create the ports, since early binding is used)

3. Open Biztalk Administration console and set the appropriate host instance for Orchestration

4. Drop the sample file (found under BizTalkDebatchingFileDropsSample File) into the folder FileDropsMD_In

5. You should see 10 messages under MD_OutAfter Mapping and 10 messages under  MD_OutBefore Mapping

Its quite straight forward to understand, if you have any doubts, read this article for explanation.

1. Set TargetNamespace

Make sure all your schemas has appropriate TargetNamespace, in general its very important to have a TargetNamespace, because BizTalk identifies the message based on the combination of TargetNamespace#RootElement combination.

2. We need to include namespaces in the XPath.

Any XPATH we use inside the orchestration must be fully qualified with the local name and namespace uri (TargetNamespace we set in the schemas) as shown below.

nRecordCount = System.Convert.ToInt32(xpath(Input, “count(/*[local-name()=’EnvelopeData’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’])”));

3. When looping through the nodes, we need to use xpaths node-set function position() .

When we are extracting the sub message from the envelope message we’ll be extracting it based on the position inside a loop. We can make use of XPATH Node-set function position() to get to the sub message as shown below

sXPath = System.String.Format(“/*[local-name()=’EnvelopeData’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://www.digitaldeposit.net/samples/schemas’ and position()={0}]”, nLoopCount);

4. Set Schemas “ElementFormDefault” property to Qualified (default is unqualified)

When elementFormDefault is set to qualified, it implies that all the elements must be explicitly qualified, either by using a prefix or setting a {default namespace}. An unqualified setting means that only the globally declared elements must be explicitly qualified, and the locally declared elements must not be qualified. Unfortunately the default setting for elementFormDefault is unqualified.

If you don’t set the elementFormDefault value to Qualified the output will be as shown below without any values.

<?xml version=”1.0″ encoding=”utf-8″?>
<ns0:MappedData xmlns:ns0=”
http://www.digitaldeposit.net/samples/schemas”>
<Id></Id>
<Company></Company>
<FName></FName>
<LName></LName>
<OrderId></OrderId>
<RecDate></RecDate>
<ShipDate></ShipDate>
</ns0:MappedData>

Once after setting the elementFormDefault to Qualifed, you’ll get the required output.

<?xml version=”1.0″ encoding=”utf-8″?>
<ns0:MappedData xmlns:ns0=”
http://www.digitaldeposit.net/samples/schemas”>
<ns0:Id>3</ns0:Id>
<ns0:Company>City Power And Light</ns0:Company>
<ns0:FName>Greg</ns0:FName>
<ns0:LName>Chapman</ns0:LName>
<ns0:OrderId>12031-ABC-0001</ns0:OrderId>
<ns0:RecDate>5/15/2005</ns0:RecDate>
<ns0:ShipDate>5/17/2005</ns0:ShipDate>
</ns0:MappedData>

You can download the entire article as a PDF document.
Message Debatching inside Biztalk Orchestration, with TargetNamespace
Author: Saravana Kumar

Saravana Kumar is the Founder and CTO of BizTalk360, an enterprise software that acts as an all-in-one solution for better administration, operation, support and monitoring of Microsoft BizTalk Server environments.

  • Anya Laur

    Thank you for your excellent article, saved me time. I have a question though – in my case my envelope schema has some fields that I need to map and I can’t figure out how to do so since aggregated message is not schema based, it is XmlDocument. What am I missing?

  • Josh Mendoza

    Hi Mr. Saravana Kumar.

    I did this process in my orquestration, and this works for me, but….. once when i split the schema i miss the namespace, i need the namespace, because i want to do a insert process in oracle database, thanks for helping.

One Platform Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

One Platform - Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

One Platform - Operations, Monitoring and Analytics Software
ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

Back to Top