title: SQL Server creates an XML namespace when default is specified
body: <p>Take this simple example:</p>
  
  <pre><code>declare @myXml xml
  set @myXML = '
  &lt;root&gt;
      &lt;line id="1"/&gt;
      &lt;line id="2"/&gt;
      &lt;line id="3"/&gt;
  &lt;/root&gt;'
  select t.c.query('.')
  from @myXml.nodes('/root/line') t(c)
  </code></pre>
  
  <p>As expected, I get back three rows, looking like this:</p>
  
  <pre><code>&lt;line id="1" /&gt;
  </code></pre>
  
  <p>However, when the XML declares its namespace (even just the default xmlns), you also need to specify that namespace in the SQL, or your result set winds up empty. I know of two ways: a <em>declare</em> statement within the nodes() method call, or a <em>with xmlnamespaces</em> statement. Let's use the latter:</p>
  
  <pre><code>declare @myXml xml
  set @myXML = '
  &lt;root xmlns="urn:somename"&gt;
      &lt;line id="1"/&gt;
      &lt;line id="2"/&gt;
      &lt;line id="3"/&gt;
  &lt;/root&gt;';
  
  with xmlnamespaces(default 'urn:somename')
  select t.c.query('.')
  from @myXml.nodes('/root/line') t(c)
  </code></pre>
  
  <p>While I now get results, there is a definite weirdness in the results. The specified namespace is added as "p1" instead of the default. So my output looks like this:</p>
  
  <pre><code>&lt;p1:line xmlns:p1="urn:somename" id="1" /&gt;
  </code></pre>
  
  <p>In <a href="http://technet.microsoft.com/en-us/library/ms187013.aspx" rel="nofollow">this Technet article</a>, the section <em>B. Declaring a default namespace</em> shows what I'm trying to achieve, but I get the result shown in <em>D. Construction using default namespaces</em>. Since my example doesn't look very much like the latter, I don't understand why I'm getting these prefixes.</p>
  
  <p><strong>Update:</strong>
  For the sake of completeness, this gives exactly the same symptom as the <em>with xmlnamespaces</em> syntax:</p>
  
  <pre><code>select t.c.query('.')
  from @myXml.nodes('declare default element namespace "urn:somename";/root/line') t(c)
  </code></pre>