title: SQLParameter of XML type with whitespace elements, loses the whitespace?
body: <p>I've got a problem with SQLParameter when I try to use one to store into a column of XML type. I am creating the parameter of SqlDbType.Xml. It appears that any XML Elements that are only white space are converted to closed elements. </p>
  
  <p>This is the same behaviour as </p>
  
  <pre><code>SELECT CAST('&lt;Cust&gt;&lt;Fname&gt;Andrew&lt;/Fname&gt;&lt;Lname&gt; &lt;/Lname&gt;&lt;/Cust&gt;' as XML) 
  VS 
  SELECT CONVERT(xml, '&lt;Cust&gt;&lt;Fname&gt;Andrew&lt;/Fname&gt;&lt;Lname&gt; &lt;/Lname&gt;&lt;/Cust&gt;', 1)
  </code></pre>
  
  <p>I'm surprised to see that as the default behaviour within SQLParameter. Is there some way to make a SQLParameter of SqlDbType.Xml care about its white space? As a shot in the dark i tried setting the Precision to 1, but that didn't help it...</p>
  
  <p>The code below ends up with this in the database</p>
  
  <pre><code>&lt;Cust&gt;&lt;Fname&gt;Andrew&lt;/Fname&gt;&lt;Lname /&gt;&lt;/Cust&gt;
  </code></pre>
  
  <p>As you can see it strips out the whitespace XML element</p>
  
  <pre><code>// CREATE TABLE T(c1 int primary key, c2 xml)
  static void Main(string[] args) {
  
  using (var Connection = new System.Data.SqlClient.SqlConnection("Data Source=localhost;Initial Catalog=Test;Integrated Security=SSPI;"))
  {
      Connection.Open();
  
      using (var Command = Connection.CreateCommand())
      {
        Command.CommandText = "INSERT INTO T VALUES (1, @s)";
  
        var XmlParameter = Command.Parameters.Add("s", System.Data.SqlDbType.Xml);
        XmlParameter.Value = "&lt;Cust&gt;&lt;Fname&gt;Andrew&lt;/Fname&gt;&lt;Lname&gt;  &lt;/Lname&gt;&lt;/Cust&gt;";
  
        Command.ExecuteNonQuery();
      }
  
      Connection.Close();
  }
  </code></pre>
  
  <p>Does anyone know of a way to solve it that isn't parsing the parameter in as binary and the converting it as part of the insert/update command?</p>
  
  <pre><code>Command.CommandText = "INSERT INTO T VALUES (1, CONVERT(xml, @s, 1))";
  </code></pre>
  
  <p>Any help or feedback would be greatly appreciated.</p>