title: Querying XML data types which have xmlns node attributes
body: <p>I have the following SQL query:</p>
  
  <pre><code>DECLARE @XMLDOC XML
  SET @XMLDOC = '&lt;Feed&gt;&lt;Product&gt;&lt;Name&gt;Foo&lt;/Name&gt;&lt;/Product&gt;&lt;/Feed&gt;'
  
  SELECT  x.u.value('Name[1]', 'varchar(100)') as Name
  from @XMLDOC.nodes('/Feed/Product') x(u)
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>Name
  ----
  Foo
  </code></pre>
  
  <p>However, if my <code>&lt;Feed&gt;</code> node has an <code>xmlns</code> attribute, then this doesn't return any results:</p>
  
  <pre><code>DECLARE @XMLDOC XML
  SET @XMLDOC = '&lt;Feed xmlns="bar"&gt;&lt;Product&gt;&lt;Name&gt;Foo&lt;/Name&gt;&lt;/Product&gt;&lt;/Feed&gt;'
  
  SELECT  x.u.value('Name[1]', 'varchar(100)') as Name
  from @XMLDOC.nodes('/Feed/Product') x(u)
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>Name
  ----
  </code></pre>
  
  <p>This only happens if I have an <code>xmlns</code> attribute, anything else works fine.</p>
  
  <p>Why is this, and how can I modify my SQL query to return results regardless of the attributes?</p>