all Technical posts

ESB Remove Namespace Pipeline Component and Nillable Nodes

During a migration from BizTalk 2006R2 to BizTalk 2016 we ran into an issue with the “ESB Remove Namespace” pipeline component. This component is available out-of-the box when the ESB Toolkit is installed and is used to remove all namespaces from a message.

After successfully completing the migration and putting the new environment in production the customer also needed to process a new message. As with the other messages received in their BizTalk environment, all of the namespaces have to be removed from the message and a new one is added. For this the customer had used the “ESB Remove Namespace” and “ESB Add Namespace” pipeline components and this setup had been successfully migrated to BizTalk 2016. For more information on these pipeline components, see: https://msdn.microsoft.com/en-us/library/ee250047(v=bts.10).aspx.

However, when the new message was received by BizTalk we received this error:

Reason: The XML Validator failed to validate.
Details: The ‘nil’ attribute is not declared.

It turned out the XSD of the new message has a field that can be nillable, in the message we received the field was indeed marked as nillable. The “ESB Remove Namespace” pipeline component removed the xsi namespace and prefix which caused the “XML validator” pipeline component to fail!

Changing the message content or the XSD was not an option since the XSD was created and maintained by the external party which was sending us the message. We ultimately ended up recreating the “ESB Remove Namespace” pipeline component into a custom pipeline component and modifying the code.

The “ESB Remove Namespace” pipeline component contains code to process the Attributes which contains this snippet:
if (string.Compare(inReader.Name, “xmlns”, StringComparison.OrdinalIgnoreCase) != 0 && !inReader.Name.StartsWith(“xmlns:”, StringComparison.OrdinalIgnoreCase))
{
                writer.WriteStartAttribute(“”, inReader.LocalName, “”);
                writer.WriteString(inReader.Value);
                writer.WriteEndAttribute();
}

We replaced this with:
if (inReader.LocalName.ToLower() == “nil” && inReader.NamespaceURI.ToLower() == “http://www.w3.org/2001/xmlschema-instance”)
{
                writer.WriteStartAttribute(inReader.Prefix, inReader.LocalName, inReader.NamespaceURI);
                writer.WriteString(inReader.Value);
                writer.WriteEndAttribute();
}
else if (String.Compare(inReader.Name, “xmlns”, StringComparison.OrdinalIgnoreCase) != 0 &&
                !inReader.Name.StartsWith(“xmlns:”, StringComparison.OrdinalIgnoreCase))
{
                writer.WriteStartAttribute(“”, inReader.LocalName, “”);
                writer.WriteString(inReader.Value);
                writer.WriteEndAttribute();
}

Now when we receive a message containing a node that is marked as nil, the custom “ESB Remove Namespace” pipeline component handles it correctly and the message is processed.

We could not find any information about the “ESB Remove Namespace” pipeline component not supporting nillable nodes on MSDN and I find it strange that the pipeline component does not support this. To me this seems like a bug.

Subscribe to our RSS feed