title: Unable to cast TEXT to XML in SQL Server
body: <p>Basically I have a column named <code>XML</code> that is of type <code>TEXT</code>; this cannot be changed for other reason, but I was wondering how I could cast it to XML.</p>
  
  <p>It gives me an error </p>
  
  <blockquote>
    <p>XML parsing: line 1, character 39, unable to switch the encoding</p>
  </blockquote>
  
  <p>when trying to do this. Is there anyways around it to still get it formatted to XML? I'm really stuck at this point.</p>
  
  <p>Data within column:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;Record&gt;
       &lt;UserGuid&gt;c624a356-9f18-403c-b404-790e79034c7d&lt;/UserGuid&gt;
  &lt;/Record&gt;
  </code></pre>
  
  <p>Here is the cast SQL code:</p>
  
  <pre><code>SELECT CAST(XML AS XML).value('(/Record/UserGuid)[1]', 'NVARCHAR(max)')
  FROM tbl_Module_RequestForms_Items
  </code></pre>