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 …
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:
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:
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
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
Excellent! I am amazed how many namespaceless XML specifications I have encountered…
Why does BT require namespaces in the first place. Namespaces just muck up the xml format and take something that is designed to be super easy to read (xml) and make it cumbersome and stupid to read. Besides, namespaces give you almost zero benefit. Why all the hassle!!!??? Who in their right mind uses them?
Why use strongtype versus sloopy typing
An xml document is ment to be read by a machine/program not by the human eye, You need the strong type in order to identify and the validate the message automatically otherwise it’s garbage in – garbage out
Thank you very much Richard for such helpful article!
I came across a similar situation today and found your post. It is very helpfull.
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 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?
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.
MemoryStream outStream = new MemoryStream();
XmlWriter writer = new XmlTextWriter(outStream, Encoding.UTF8);
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
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:
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
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!
Many thanks for this article. Solved one of my big problems.
Thanks for the article, however, when I changed the code as suggested to be “xmlns”, and deployed into the pipelines folder in VS I get this error: “You have selected an invalid pipeline component assembly. Please check security settings for the assembly if you are loading it from an UNC path.” Any ideas?