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



Saravana
February 23, 2007
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
chuck duffy
February 28, 2007
Excellent! I am amazed how many namespaceless XML specifications I have encountered…
Chuck
Andrew Veresov
March 2, 2007
Thank you very much Richard for such helpful article!
Steef-Jan Wiggers
May 31, 2007
Hi Richard,
I came across a similar situation today and found your post. It is very helpfull.
Thanks,
Steef-Jan
Magnus M
June 4, 2007
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.
Gopal
June 14, 2007
…..
Thank you very much Richard, I came across a similar situation today and found your post. It is very helpfull.
Thanks
Gopal
george
March 26, 2008
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.
Richard Seroter
March 26, 2008
George, have you installed the Enterprise Adapters, which provide this pipeline component?
Frank
August 14, 2008
Where can I find a download of the adapter pack for enterprise applications?
Richard Seroter
August 14, 2008
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.
Kelvin Tse
September 19, 2008
Hi Richard, one more article from you that saves me hours of work. THANK YOU !!
Richard Seroter
September 19, 2008
Always nice to hear. Thanks Kelvin.
Martin Bring
October 29, 2008
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?
Martin Bring
October 29, 2008
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);
Richard Seroter
October 29, 2008
Thanks for the tip, Martin.
Srini
January 22, 2009
Can anybody provide code for this!!
Andreas Moehlenbrock
April 13, 2009
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
Andreas Moehlenbrock
April 13, 2009
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
Anders Ekman
August 25, 2010
When I first glanced at your articel I thought, this is the solution I need but then my eyes fell on the words “If you had installed..”. We have not so I guess our problems have to be solved in some other way. But thanks anyway
Saulias
September 8, 2010
Hi,
If root tag has an attribute, then when adding namespace it removes the attribute.
I have XML with …. When this XML goes through pipeline i get , the attributes get cut off.
Have anyone had this issue?
I would appreciate your help!
BR,
Saule