title: Querying Serialized Dictionary in XML Column
body: <p>I have a Dictionary that I'm serializing in C# and storing in an XML column on  MSSQL Server. The serialized XML looks like this:</p>
  
  <pre><code>&lt;ArrayOfKeyValueOfstringanyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
    &lt;KeyValueOfstringanyType&gt;
       &lt;Key&gt;code&lt;/Key&gt;&lt;Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:string"&gt;WFR 052&lt;/Value&gt;
    &lt;/KeyValueOfstringanyType&gt;
    &lt;KeyValueOfstringanyType&gt;
      &lt;Key&gt;type&lt;/Key&gt;&lt;Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:string"&gt;Newsletter&lt;/Value&gt;
    &lt;/KeyValueOfstringanyType&gt;
  &lt;/ArrayOfKeyValueOfstringanyType&gt;
  </code></pre>
  
  <p>Ultimately, I want to get the Value, where the Key is "code". The first step I took was to just get the first value, regardless of key.</p>
  
  <pre><code>SELECT [xml_column].value('(/ArrayOfKeyValueOfstringanyType/KeyValueOfstringanyType/Value)[1]','varchar(255)') as val
  FROM [my_table]
  </code></pre>
  
  <p>I get null values back. I know it has something to do with the namespaces, because when I try the same query with the namespaces removed, I get a value. I've seen some other scenarios with namespaces, but my XML format is a bit different, and I'm struggling to find the right syntax.</p>
  
  <p>Here's another question I looked at:</p>
  
  <p><a href="https://stackoverflow.com/questions/10513800/xml-field-query">XML Field - Query</a></p>