title: How to make ASP.NET Core return XML result?
body: <pre><code>[HttpGet]
  [HttpPost]
  public HttpResponseMessage GetXml(string value)
  {
      var xml = $"&lt;result&gt;&lt;value&gt;{value}&lt;/value&gt;&lt;/result&gt;";
      return new HttpResponseMessage
     {
         Content = new StringContent(xml, Encoding.UTF8, "application/xml")
     };
  }
  </code></pre>
  
  <p>I called the action using Swagger and passed this parameter 'text value'</p>
  
  <p><strong>Expected</strong> result should be an XML file like this: text value</p>
  
  <p><strong>Actual Result:</strong> strange json result without the passed value! <a href="https://www.screencast.com/t/uzcEed7ojLe" rel="noreferrer">https://www.screencast.com/t/uzcEed7ojLe</a></p>
  
  <p>I tried the following solutions but did not work:</p>
  
  <pre><code>services.AddMvc().AddXmlDataContractSerializerFormatters();
  services.AddMvc().AddXmlSerializerFormatters();
  </code></pre>