title: Different behaviour when using ELEMENTS XSINIL on SQL 2005 and SQL 2012
body: <p>I have a legacy problem between SQL 2005 (9.0.5057) and SQL 2012 (11.0.3128). When I run the following sample SQL query on SQL 2005 and then SQL 2012 I get different results:</p>
  
  <pre><code>select
    0 'test1/@old', null 'test1',
    null 'test2/@old', 2 'test2',
    2 'test3/@old', 2 'test3',
    null 'test4/@old', null 'test4'
  FOR XML PATH('Data'), ELEMENTS XSINIL
  </code></pre>
  
  <p>For SQL 2005 the result is:</p>
  
  <pre><code>&lt;Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;test1 old="0" /&gt;
    &lt;test2&gt;2&lt;/test2&gt;
    &lt;test3 old="2"&gt;2&lt;/test3&gt;
    &lt;test4 xsi:nil="true" /&gt;
  &lt;/Data&gt;
  </code></pre>
  
  <p>For SQL 2012 the result is:</p>
  
  <pre><code>&lt;Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;test1 old="0" xsi:nil="true" /&gt;
    &lt;test2&gt;2&lt;/test2&gt;
    &lt;test3 old="2"&gt;2&lt;/test3&gt;
    &lt;test4 xsi:nil="true" /&gt;
  &lt;/Data&gt;
  </code></pre>
  
  <p>Test1 is where the problem is occurring. The behavior for SQL 2012 is correct but I am struggling to find either a patch or work around for this in SQL 2005.</p>
  
  <p>I ran the same test on SQL Server 2008 R2 (10.50.2500) but get the SQL 2005 result.</p>
  
  <p>Am I missing something somewhere?</p>