none
BizTalk map preserving whitespace

    Question

  • According to the documentation at MSDN (http://msdn.microsoft.com/en-us/library/aa561674.aspx), BizTalk maps should not preserve whitespace.

    However, after a recent upgrade from 2006 to 2006 R2 our system seems now to be preserving whitespace.

    For example, when the element Field in the following XML:

    <ns0:Root xmlns:ns0="http://BizTalk_Server_Project2.source1">  
      <Field> 
      </Field> 
    </ns0:Root> 

    gets mapped to an element called Field1 in a slightly different schema:

    <ns0:Root Field1="&#xD;&#xA;  " xmlns:ns0="http://BizTalk_Server_Project2.destination> 

    the whitespace remains in place.

    This is causing us a problem because the max length of the destination field is 1.

    I can't check (because the upgrade process does not seem to be reversible) but I don't believe this was the case prior to R2.

    Can anyone tell me if this is correct behaviour, and whether it has changed in R2?

    Many thanks,
    Alister.
    Wednesday, January 07, 2009 2:28 PM

Answers

  • OK, after some digging in Reflector, I have got to the bottom of this.  The behaviour has indeed changed in R2, although this is not documented anywhere that I can find.

    In BizTalk 2006 (non-R2), the method Microsoft.BizTalk.ScalableTransformation.BTSXslTransform.DoStandardTransformation looks like this:

    private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)  
    {  
        Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation"new object[0]);  
        XPathDocument input = new XPathDocument(strm);  
        this.xform.Transform(input, args, output, resolver);  
        Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation"new object[0]);  

    But in R2 it looks like this:

    private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)  
    {  
        Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation"new object[0]);  
        if (legacyWhitespaceBehavior)  
        {  
            this.xform.Transform(new XPathDocument(strm), args, output, resolver);  
        }  
        else 
        {  
            this.xform.Transform(new XPathDocument(new XmlTextReader(strm), XmlSpace.Preserve), args, output, resolver);  
        }  
        Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation"new object[0]);  

    Digging a little further, I found that legacyWhitespaceBehaviour gets set in the static constructor:

    static BTSXslTransform()  
    {  
        Transform_CLSID = new Guid("{917718A6-67E1-47c0-9267-2164A0DF632B}");  
        legacyWhitespaceBehavior = false;  
        defaultAutoSwitchThreshold = 0x100000;  
        int registryValue = Utils.GetRegistryValue("TransformThreshold", @"Software\Microsoft\BizTalk Server\3.0\Administration");  
        if (registryValue > 0)  
        {  
            defaultAutoSwitchThreshold = registryValue;  
        }  
        if (Utils.GetRegistryValue("LegacyWhitespace", @"Software\Microsoft\BizTalk Server\3.0\Administration") > 0)  
        {  
            legacyWhitespaceBehavior = true;  
        }  

    And sure enough, by creating the registry key HKLM\Software\Microsoft\BizTalk Server\3.0\Administration\LegacyWhitespace and setting it to 1, I get the result I was expecting.

    Googling for "biztalk legacywhitespace" returns no results, so this is apparently a completely undocumented feature  >:(
    Thursday, January 08, 2009 12:35 PM

All replies

  • Update: one of my colleagues has just run the same test in BizTalk 2006 (non-R2) and confirmed that the behaviour is different.

    In BizTalk 2006 we get this as the output:

    <ns0:Root Field1="" xmlns:ns0="http://BizTalk_Server_Project2.destination>  

    This is a serious issue for us because our system expects the whitespace to be stripped; and unfortunately we need R2 because of a critical bugfix it contains in another area.

    Does anyone know how we can revert to the previous behaviour?
    Wednesday, January 07, 2009 2:38 PM
  • OK, after some digging in Reflector, I have got to the bottom of this.  The behaviour has indeed changed in R2, although this is not documented anywhere that I can find.

    In BizTalk 2006 (non-R2), the method Microsoft.BizTalk.ScalableTransformation.BTSXslTransform.DoStandardTransformation looks like this:

    private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)  
    {  
        Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation"new object[0]);  
        XPathDocument input = new XPathDocument(strm);  
        this.xform.Transform(input, args, output, resolver);  
        Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation"new object[0]);  

    But in R2 it looks like this:

    private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)  
    {  
        Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation"new object[0]);  
        if (legacyWhitespaceBehavior)  
        {  
            this.xform.Transform(new XPathDocument(strm), args, output, resolver);  
        }  
        else 
        {  
            this.xform.Transform(new XPathDocument(new XmlTextReader(strm), XmlSpace.Preserve), args, output, resolver);  
        }  
        Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation"new object[0]);  

    Digging a little further, I found that legacyWhitespaceBehaviour gets set in the static constructor:

    static BTSXslTransform()  
    {  
        Transform_CLSID = new Guid("{917718A6-67E1-47c0-9267-2164A0DF632B}");  
        legacyWhitespaceBehavior = false;  
        defaultAutoSwitchThreshold = 0x100000;  
        int registryValue = Utils.GetRegistryValue("TransformThreshold", @"Software\Microsoft\BizTalk Server\3.0\Administration");  
        if (registryValue > 0)  
        {  
            defaultAutoSwitchThreshold = registryValue;  
        }  
        if (Utils.GetRegistryValue("LegacyWhitespace", @"Software\Microsoft\BizTalk Server\3.0\Administration") > 0)  
        {  
            legacyWhitespaceBehavior = true;  
        }  

    And sure enough, by creating the registry key HKLM\Software\Microsoft\BizTalk Server\3.0\Administration\LegacyWhitespace and setting it to 1, I get the result I was expecting.

    Googling for "biztalk legacywhitespace" returns no results, so this is apparently a completely undocumented feature  >:(
    Thursday, January 08, 2009 12:35 PM
  • Alister,

    I'm having the same issue in BizTalk 2006 R2 so i followed to create Reg Key but no luck. Pls help me.

    Thanks,
    Raja Kumaravel
    Tuesday, March 31, 2009 10:38 AM
  • Hi,
    Alister has provided solution for this issue:
    open registry on R2 Biztalk box and
    create new Dword named LegacyWhitespace under
    by creating the registry key
    HKEY_LOCAL_MACHINE\Software\Microsoft\BizTalk Server\3.0\Administration
    and setting it to 1

    KiranMP
    Tuesday, March 31, 2009 10:45 AM
  • Hi,

    I created the same key, recycled hosts and rebooted server as well.

    I am still getting the same error.

    What am i doing wrong?

    Thursday, May 28, 2009 5:09 PM
  • Hi,

    I created the same key, recycled hosts and rebooted server as well.

    I am still getting the same error.

    What am i doing wrong?


    Our server was Win 2003 X64. But the hosts were running as 32 bit.
    This article states the location for 32 bit apps on a 64 bit OS. After updating in this location it started to work

    http://support.microsoft.com/default.aspx/kb/896459

     For 32 bit applications running on 64 bit OS the registry settings are stored under HKLM\Software\WOW6432Node

     

    • Proposed as answer by biztodo Friday, May 29, 2009 4:22 PM
    Friday, May 29, 2009 4:22 PM
  • if triming is taken care in th R2 then this would logically incorrect..it should not behave like this n it is also not...

    its as simple as this...when u pass a string to the u should expect the same string. so when u give xml as

    <ns0:Root xmlns:ns0="http://BizTalk_Server_Project2.source1">  
      <Field> 
      </Field> 
    </ns0:Root>

    this itself clearly shows there is a newline charecter in the Field element. so there would be an newline charater expected in in the destination.

    for handling this one should use triming functiods

    @Alister Whitford
    please provide relevant proof for wat u say...it sounds intersting

    Tuesday, July 28, 2009 11:47 AM
  • well we have done enough tests about this and confirmed that R2 is preserving whitespaces. also we checked using reflector.
    by changing/creating registry value we could get expected output.
    KiranMP
    Tuesday, July 28, 2009 11:59 AM
  • Hello,

    I just upgrade from <BTS 2006 R2> to <BTS 2006 R2 SP1> and now BizTalk Maps do not preserve whitespace.

    BizTalk is installed on a Win 2003 Server R2 32 bit.

    Does anayone know how to solve this problem ?

    Thanks,

    Jacques.

    Friday, November 05, 2010 1:44 PM