<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
    <title>Alister's Occasional BizTalk &amp; .NET Blog</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/alister/Atom.aspx" />
    <subtitle type="html"> </subtitle>
    <id>http://geekswithblogs.net/alister/Default.aspx</id>
    <author>
        <name>Alister</name>
        <uri>http://geekswithblogs.net/alister/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2009-11-02T23:26:08Z</updated>
    <entry>
        <title>Difference in whitespace preservation in maps between BizTalk 2006 and BizTalk 2006 R2</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/alister/archive/2009/01/08/difference-in-whitespace-preservation-in-maps-between-biztalk-2006-and.aspx" />
        <id>http://geekswithblogs.net/alister/archive/2009/01/08/difference-in-whitespace-preservation-in-maps-between-biztalk-2006-and.aspx</id>
        <published>2009-01-08T12:50:10-12:00:00</published>
        <updated>2009-11-02T22:53:14Z</updated>
        <summary type="html">According to the documentation at MSDN, BizTalk maps should not preserve whitespace.

However, after a recent upgrade from 2006 to 2006 R2 our test platform suddenly started preserving whitespace in maps.

Reflector analysis showed that the default behaviour has indeed been changed, and that the old behaviour can be re-enabled by using an undocument registry key...</summary>
        <content type="html">&lt;p&gt;This is a very irritating issue which has taken me about two days to chase down - and all thanks to an apparently undocumented change between BizTalk 2006 and BizTalk 2006 R2 &lt;img alt="" src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/angry_smile.gif" /&gt;&lt;/p&gt;
&lt;p&gt;According to the documentation at MSDN (&lt;a href="http://msdn.microsoft.com/en-us/library/aa561674.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa561674.aspx&lt;/a&gt;), BizTalk maps should not preserve whitespace.&lt;br /&gt;
&lt;br /&gt;
However, after a recent upgrade from 2006 to 2006 R2 our test platform started rejecting records which it had previously processed without complaint.  Initial analysis showed that it had suddenly started preserving whitespace in maps.&lt;br /&gt;
&lt;br /&gt;
For example, in BizTalk 2006 (non-R2) when the element Field in the following XML:&lt;/p&gt;
&lt;pre&gt;&amp;lt;ns0:Root xmlns:ns0="http://BizTalk_Server_Project2.source1"&amp;gt;   &lt;br /&gt;  &amp;lt;Field&amp;gt;  &lt;br /&gt;  &amp;lt;/Field&amp;gt;  &lt;br /&gt;&amp;lt;/ns0:Root&amp;gt;&lt;/pre&gt;
&lt;p&gt;gets mapped to an element called Field1 in a slightly different schema:&lt;/p&gt;
&lt;pre&gt;&amp;lt;ns0:Root Field1=&lt;font style="BACKGROUND-COLOR: #ccffcc"&gt;""&lt;/font&gt; xmlns:ns0="http://BizTalk_Server_Project2.destination&amp;gt; &lt;/pre&gt;
&lt;p&gt;the whitespace between &amp;lt;Field&amp;gt; and &amp;lt;/Field&amp;gt; is stripped away (as expected).&lt;/p&gt;
&lt;p&gt;But after upgrading to R2, the behaviour mysteriously changes and the output is now:&lt;/p&gt;
&lt;pre&gt;&amp;lt;ns0:Root Field1=&lt;font style="BACKGROUND-COLOR: #ffcc99"&gt;"&amp;amp;#xD;&amp;amp;#xA;  "&lt;/font&gt; xmlns:ns0="http://BizTalk_Server_Project2.destination&amp;gt;&lt;/pre&gt;
&lt;p&gt;Eventually, after digging about in Reflector, I found out why.  In BizTalk 2006 (non-R2), the method Microsoft.BizTalk.ScalableTransformation.BTSXslTransform.DoStandardTransformation looks like this:&lt;/p&gt;
&lt;pre&gt;private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)   &lt;br /&gt;{   &lt;br /&gt;    Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation", new object[0]);   &lt;br /&gt;    XPathDocument input = new XPathDocument(strm);   &lt;br /&gt;    this.xform.Transform(input, args, output, resolver);   &lt;br /&gt;    Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation", new object[0]);   &lt;br /&gt;}  &lt;/pre&gt;
&lt;p&gt;&lt;font face="Arial"&gt;But in R2 it looks like this:&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt;private void DoStandardTransform(Stream strm, XsltArgumentList args, Stream output, XmlResolver resolver)   &lt;br /&gt;{   &lt;br /&gt;    Trace.Tracer.TraceMessage(4, "LMT:Use Standard Transformation", new object[0]);   &lt;br /&gt;    if (&lt;font style="BACKGROUND-COLOR: #ccffcc"&gt;legacyWhitespaceBehavior&lt;/font&gt;)   &lt;br /&gt;    {   &lt;br /&gt;        this.xform.Transform(new XPathDocument(strm), args, output, resolver);   &lt;br /&gt;    }   &lt;br /&gt;    &lt;font style="BACKGROUND-COLOR: #ffcc99"&gt;else&lt;br /&gt;&lt;/font&gt;    {   &lt;br /&gt;        this.xform.Transform(new XPathDocument(new XmlTextReader(strm), &lt;font style="BACKGROUND-COLOR: #ffcc99"&gt;XmlSpace.Preserve&lt;/font&gt;), args, output, resolver);   &lt;br /&gt;    }   &lt;br /&gt;    Trace.Tracer.TraceMessage(4, "LMT:Done with Standard Transformation", new object[0]);   &lt;br /&gt;}  &lt;/pre&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Digging a little further, I found that legacyWhitespaceBehaviour gets set in the static constructor:&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt;static BTSXslTransform()   &lt;br /&gt;{   &lt;br /&gt;    Transform_CLSID = new Guid("{917718A6-67E1-47c0-9267-2164A0DF632B}");   &lt;br /&gt;    legacyWhitespaceBehavior = false;   &lt;br /&gt;    defaultAutoSwitchThreshold = 0x100000;   &lt;br /&gt;    int registryValue = Utils.GetRegistryValue("TransformThreshold", @"Software\Microsoft\BizTalk Server\3.0\Administration");   &lt;br /&gt;    if (registryValue &amp;gt; 0)   &lt;br /&gt;    {   &lt;br /&gt;        defaultAutoSwitchThreshold = registryValue;   &lt;br /&gt;    }   &lt;br /&gt;    if (Utils.GetRegistryValue("LegacyWhitespace", @"&lt;font style="BACKGROUND-COLOR: #ccffcc"&gt;Software\Microsoft\BizTalk Server\3.0\Administration&lt;/font&gt;") &amp;gt; 0)   &lt;br /&gt;    {   &lt;br /&gt;        &lt;font style="BACKGROUND-COLOR: #ccffcc"&gt;legacyWhitespaceBehavior = true;&lt;/font&gt;   &lt;br /&gt;    }   &lt;br /&gt;}  &lt;/pre&gt;
&lt;p&gt;&lt;font face="Arial"&gt;And sure enough, by creating the registry key HKLM\Software\Microsoft\BizTalk Server\3.0\Administration\LegacyWhitespace and setting it to 1, I got the result I was expecting.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Googling for "biztalk legacywhitespace" returns no results, &lt;/font&gt;so this is apparently a completely undocumented feature  &lt;img alt="" src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/angry_smile.gif" /&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/alister/aggbug/128483.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/alister/comments/128483.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/alister/comments/commentRss/128483.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/alister/services/trackbacks/128483.aspx</trackback:ping>
    </entry>
</feed>