none
Handle TargetNamespace in BizTalk RRS feed

  • Question

  • Hello Gents,

    I wish to remove the Targetnamespace from the outgoing message at the send port. Is it possible to do it out of box in BizTalk or I need to write some custom component for that?

    Wednesday, June 1, 2016 9:41 PM

Answers

  • Hello,

    If you wish to do it at send port.

    You could use the pipeline component provided with the ESB Toolkit for this purpose. Refer: http://msdn.microsoft.com/en-us/library/ee250047(v=bts.10).aspx

    You could optionally use this Code Project sample http://www.codeproject.com/Articles/146182/Change-Namespace-of-a-Message-in-a-Custom-Pipeline

    If you have orchestration, you call helper method in Orchestration with following code which removes all the namespace references in the message:

    private static string RemoveNamespace(XmlDocument xdoc)
    {
      // Regex to search for either xmlns:nsN="..." or xmlns="..."
      const string pattern = @"xmlns:?(\w+)?=""[\w:/.]*""";
      string xml = xdoc.OuterXml;
     
      Regex replace = new Regex(pattern);
      // Replace all occurances of the namespace declaration
      string temp = replace.Replace(xml, String.Empty);
      foreach (Match match in replace.Matches(xml))
      {
        // Loop through each Match in the Regex, this gives us the namespace aliases found
        if (match.Success && match.Groups.Count > 1)
        {
          if (!String.IsNullOrEmpty( match.Groups[1].Value))
          {
            Regex alias = new Regex(@"\b" + match.Groups[1].Value + ":");
            // Replace all occurances of the
            temp = alias.Replace(temp, String.Empty);
          }
        }
      }
      return temp;
    }

    Reference: Changing / Removing document namespaces


    Rachit Sikroria (Microsoft Azure MVP)

    Wednesday, June 1, 2016 9:45 PM
    Moderator
  • Why do you want to do this?  Is it because the target system cannot handle namespaces?

    This really shouldn't be an issue since the Target Namespace is not required anywhere so the most correct option is to simple remove it from the Schema.  If you use a Map to create the message, I will emit no namespace (well, technically an empty namespace).

    Basically, you shouldn't have to remove it.  The app should just not add it in the first place.

    BTW, string manipulation, especially of Xml, is risky and rarely a good idea.  I would no use the sample posted above. :(

    • Marked as answer by ssimon11 Thursday, June 2, 2016 5:21 PM
    Thursday, June 2, 2016 11:54 AM
    Moderator

All replies

  • Hello,

    If you wish to do it at send port.

    You could use the pipeline component provided with the ESB Toolkit for this purpose. Refer: http://msdn.microsoft.com/en-us/library/ee250047(v=bts.10).aspx

    You could optionally use this Code Project sample http://www.codeproject.com/Articles/146182/Change-Namespace-of-a-Message-in-a-Custom-Pipeline

    If you have orchestration, you call helper method in Orchestration with following code which removes all the namespace references in the message:

    private static string RemoveNamespace(XmlDocument xdoc)
    {
      // Regex to search for either xmlns:nsN="..." or xmlns="..."
      const string pattern = @"xmlns:?(\w+)?=""[\w:/.]*""";
      string xml = xdoc.OuterXml;
     
      Regex replace = new Regex(pattern);
      // Replace all occurances of the namespace declaration
      string temp = replace.Replace(xml, String.Empty);
      foreach (Match match in replace.Matches(xml))
      {
        // Loop through each Match in the Regex, this gives us the namespace aliases found
        if (match.Success && match.Groups.Count > 1)
        {
          if (!String.IsNullOrEmpty( match.Groups[1].Value))
          {
            Regex alias = new Regex(@"\b" + match.Groups[1].Value + ":");
            // Replace all occurances of the
            temp = alias.Replace(temp, String.Empty);
          }
        }
      }
      return temp;
    }

    Reference: Changing / Removing document namespaces


    Rachit Sikroria (Microsoft Azure MVP)

    Wednesday, June 1, 2016 9:45 PM
    Moderator
  • Why do you want to do this?  Is it because the target system cannot handle namespaces?

    This really shouldn't be an issue since the Target Namespace is not required anywhere so the most correct option is to simple remove it from the Schema.  If you use a Map to create the message, I will emit no namespace (well, technically an empty namespace).

    Basically, you shouldn't have to remove it.  The app should just not add it in the first place.

    BTW, string manipulation, especially of Xml, is risky and rarely a good idea.  I would no use the sample posted above. :(

    • Marked as answer by ssimon11 Thursday, June 2, 2016 5:21 PM
    Thursday, June 2, 2016 11:54 AM
    Moderator
  • Hi,

    Are you planning to remove one specific namespace or list of namespaces on a message? As already mentioned avoid string manipulation, that will cause more issues if there is hidden bug.

    If you are using Biztalk 2013, out of box there are ESB pipelinecomponents to remove and add namespaces. Basic functionality of these should work well, although there are few corner cases which are not fully addressed. 

    Regards

    K

    Thursday, June 2, 2016 1:11 PM