title: Replace “&lt;” and “&gt;” with “<” and “>” in sql server
body: <p>Hi I am new to for xml </p>
  
  <p>I have a query like this </p>
  
  <pre><code>SELECT  ProjectId, 
         ProjectCode, 
         ProjectName, 
         TechId, 
        -- LocationId, 
  
        ( SELECT GeoId,PoliticalDivisionId ,GeographicLocationName,IsoCode,Longitude,Latitude,ParentLocationId,
         t2.CreatedBy,t2.CreatedOn,t2.LastUpdatedBy,t2.LastUpdatedOn
      FROM GeographicLocation t2
      WHERE GeoId = t1.LocationId
      FOR XML  PATH('Location') ),
         RtoId, 
         CreatedBy,
         CreatedOn,
         LastUpdatedBy,
         LastUpdatedOn
  FROM Project t1
  where ProjectId=1
  FOR XML PATH('ProjectInfo')
  </code></pre>
  
  <p>it return the xml as </p>
  
  <pre><code>&lt;ProjectInfo&gt;
  &lt;ProjectId&gt;1&lt;/ProjectId&gt;
  &lt;ProjectCode&gt;US-W1-00001&lt;/ProjectCode&gt;
  &lt;ProjectName&gt;Rees&lt;/ProjectName&gt;
  &lt;TechId&gt;1&lt;/TechId&gt;
  &amp;lt;Location&amp;gt;&amp;lt;GeoId&amp;gt;235&amp;lt;/GeoId&amp;gt;&amp;lt;PoliticalDivisionId&amp;gt;2&amp;lt;/PoliticalDivisionId&amp;gt;&amp;lt;GeographicLocationName&amp;gt;UNITED STATES&amp;lt;/GeographicLocationName&amp;gt;&amp;lt;IsoCode&amp;gt;US&amp;lt;/IsoCode&amp;gt;&amp;lt;/Location&amp;gt;
  &lt;RtoId&gt;3&lt;/RtoId&gt;
  &lt;CreatedBy&gt;1&lt;/CreatedBy&gt;
  &lt;CreatedOn&gt;2013-06-30T20:55:21.587&lt;/CreatedOn&gt;
  &lt;LastUpdatedBy&gt;1&lt;/LastUpdatedBy&gt;
  &lt;LastUpdatedOn&gt;2013-06-30T20:55:21.587&lt;/LastUpdatedOn&gt;
  </code></pre>
  
  <p>
  prject tags are shown in the form &lt; and > . But inner tags of Location are shown as “&lt;” and “&gt;”  how do I replace them with &lt; and ></p>
  
  <p><strong>Update</strong> : there was a small error in the question . inner xml was not for rtoid , it was for Location </p>
  
  <p>I updated query as </p>
  
  <pre><code>SELECT  ProjectId, 
         ProjectCode, 
         ProjectName, 
         TechId, 
        -- LocationId, 
  
        replace(replace( ( SELECT GeoId,PoliticalDivisionId ,GeographicLocationName,IsoCode,Longitude,Latitude,ParentLocationId,
         t2.CreatedBy,t2.CreatedOn,t2.LastUpdatedBy,t2.LastUpdatedOn
      FROM GeographicLocation t2
      WHERE GeoId = t1.LocationId
      FOR XML  PATH('Location') ), '&amp;lt;', '&lt;'), '&amp;gt;', '&gt;'),
         RtoId, 
         CreatedBy,
         CreatedOn,
         LastUpdatedBy,
         LastUpdatedOn
  FROM Project t1
  where ProjectId=1
  FOR XML PATH('ProjectInfo')
  </code></pre>
  
  <p>but still its the same </p>