Did you know that BizTalk Server has a hidden pipeline component that can add namespaces to inbound documents?
Often, you’ll find that you’re retrieving XML data from a system where no namespace has been provided. This can cause issues for BizTalk Server given that namespace#root is the global unique identifier for messages. If you had installed the BizTalk Adapters for Enterprise Applications, you’d find a Visual Studio.NET project located at:
C:\Program Files\Microsoft BizTalk Adapters for Enterprise Applications\Pipeline Component
This is a custom pipeline component which adds namespaces to messages. For instance, let’s say I have the following XML input coming in …
<InputSchema>
<Node1>Node1_0</Node1>
<Node2>Node2_0</Node2>
</InputSchema>
I can create a receive pipeline with my new SetNSForMsg custom pipeline component.
Notice that I can type in a namespace that will be applied to the message. After deploying this pipeline and running the above message through, I get an output XML message looking like this:
<InputSchema targetNamespace=”http://Blog.BizTalk.NSPipelineTest”>
<Node1>Node1_0</Node1>
<Node2>Node2_0</Node2>
</InputSchema>
I stared at that for a few moments and something didn’t look right. I added an XML Disassembler pipeline to my receive pipeline and redeployed. Now when I processed the original message, it got suspended with a notice that an unrecognized format was received. I realized that the component is setting the targetNamespace value vs. setting up the xmlns value the message needed. So, I went into the provided custom pipeline component’s Execute method and changed the line message.DocumentElement.SetAttribute(”targetNamespace“, targetNS); to message.DocumentElement.SetAttribute(”xmlns“, targetNS);. So my current receive pipeline looks like this:
My output messages now look like this:
<InputSchema xmlns=”http://Blog.BizTalk.NSPipelineTest”>
<Node1>Node1_0</Node1>
<Node2>Node2_0</Node2>
</InputSchema>
Now THAT’S what I’m looking for. Just to be sure that the disassembling actually succeeded, I stopped the send port, thus suspending the outbound message. Inspecting that message shows me that the Message Type was indeed set:
Sweet. One final cool thing. Now that I have this pipeline, I can use the BizTalk Server 2006 feature to modify pipeline configuration settings for EACH receive location that uses it. You can reuse this pipeline over and over, and just modify the namespace value and document schema.
While on the topic of pipelines, don’t forget to download Tomas’ fancy new PipelineTesting library for running unit tests on your pipeline components.
Technorati Tags: BizTalk
RSS Feed

Richard
Very Good article and it will be usefull to all the biztalk guys who struggle with name spaces often.Was looking for this kind of article for while when trying to process xml messages with no name spaces
Thanks
Saravana Ramkumar
Excellent! I am amazed how many namespaceless XML specifications I have encountered…
Chuck
Thank you very much Richard for such helpful article!
Hi Richard,
I came across a similar situation today and found your post. It is very helpfull.
Thanks,
Steef-Jan
Darn, I wrote my own and now I discovered this. But I needed an validation of the message anyway which I added as a property for the decode component.
…..
Thank you very much Richard, I came across a similar situation today and found your post. It is very helpfull.
Thanks
Gopal
Hi Richard,
Thanks for this good info, I am also experiencing the same problem I tried what u said but I could not get the result. I have tried with Biztalk 2006 Enterprise server. Am i missing any pre-requisite for testing this.
George, have you installed the Enterprise Adapters, which provide this pipeline component?
Where can I find a download of the adapter pack for enterprise applications?
Hi Frank,
The full download is available via MSDN subscriber download, or, on your BizTalk 2006 media. There isn’t a public-facing download that I’m aware of.
Hi Richard, one more article from you that saves me hours of work. THANK YOU !!
Always nice to hear. Thanks Kelvin.
Any problem with empty element?
After introducing this component in my pipeline I get carriage return + line feed in elements that are empty.
This affects mapping to outgoing flat file in a bad way.
Any one experience this?
Solved – “Any problem with empty element?”
I added a XmlWriter before writing to stream, then it corrects the problem with CR LF in empty elements.
Regards
Martin Bring
———————-
//message.DocumentElement.SetAttribute(”targetNamespace”, targetNS);
message.DocumentElement.SetAttribute(”xmlns”, targetNS);
MemoryStream outStream = new MemoryStream();
XmlWriter writer = new XmlTextWriter(outStream, Encoding.UTF8);
//message.Save(outStream);
message.Save(writer);
Thanks for the tip, Martin.
Can anybody provide code for this!!
Thank you very much for this article, very helpful. I was looking kind of long time, from where I can install “BizTalk Adapters for Enterprise Applications”. Finally I found them on the BizTalk DVD in the folder D:\English\BizTalkServer2006R2\LineofBusinessAdaptersDeveloperEdition\setup.exe
Cheers
Andreas
I just figured out, Microsoft has already his own component to add and remove namespace. Just “choose items” from the toolbox inside Visual Studio and select “BizTalk Pipeline Components” and “ESB Add Namespace”
The msdn arcticle is also talking about removing namespace:
http://msdn.microsoft.com/en-us/library/cc789137.aspx
Regards
Andreas