title: SQL Server query XML xpath empty namespace
body: <p>I encountered a strange behavior on SQL Server 2008 R2 when performing a Xpath query on a XML field with nodes which have an empty namespace.</p>
  
  <p>This query doesn't return results:</p>
  
  <pre><code>[xml_field].query('/RootNode/NodeWithEmptyNamespace')
  </code></pre>
  
  <p>This query returns results:</p>
  
  <pre><code>[xml_field].query('/dft:RootNode/NodeWithEmptyNamespace')
  </code></pre>
  
  <p>For clarification this query also returns results so no prefix is mandatory for root node (and probably default namespace):</p>
  
  <pre><code>[xml_field].query('/RootNode')
  </code></pre>
  
  <p>According to the <a href="http://www.w3.org/TR/xml-names/#defaulting" rel="nofollow">XML namespace default documation</a> when empty namespace is defined the namespace is none.</p>
  
  <p>The XML in the database is the following:</p>
  
  <pre><code>&lt;RootNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org"&gt;
    &lt;otherNode&gt;Dummy data&lt;/otherNode&gt;
    &lt;NodeWithEmptyNamespace xmlns=""&gt;Other dummy data&lt;/NodeWithEmptyNamespace&gt;
  &lt;/RootNode&gt;
  </code></pre>
  
  <p>The full query:</p>
  
  <pre><code>WITH XMLNAMESPACES ('http://tempuri.org' as dft)
  SELECT TOP 150 [ID],
         [xml_field].query('/dft:RootNode/NodeWithEmptyNamespace')
    FROM [database];
  </code></pre>
  
  <p>Does anyone have an explanation for this behavior or is this a bug?</p>