title: WebAPI OData $format to xml
body: <p>for my WebAPI OData application, im trying to give my client (browser) the decision what format the data output should be. as <strong>$format</strong> is not implemented yet in WebAPI OData, im using Raghuramn's example here: <a href="https://gist.github.com/raghuramn/5556691" rel="nofollow">https://gist.github.com/raghuramn/5556691</a></p>
  
  <pre><code>var queryParams = request.GetQueryNameValuePairs();
  var dollarFormat = queryParams.Where(kvp =&gt; kvp.Key == "$format").Select(kvp =&gt; kvp.Value).FirstOrDefault();
  
  if (dollarFormat != null)
  {
      request.Headers.Accept.Clear();
      request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(dollarFormat));
  
      // remove $format from the request.
      request.Properties[HttpPropertyKeys.RequestQueryNameValuePairsKey] = queryParams.Where(kvp =&gt; kvp.Key != "$format");
  }
  </code></pre>
  
  <p>This works for JSON ($format=application/json;odata=fullmetadata) and JSON light (format=application/json;odata=light) but so far not for xml.</p>
  
  <p>if i add <strong>$format=application/XML</strong> to the querystring, it still outputs to json light. how do i force XML output?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>even if i <em>force xml</em> in Fiddler by sending 
  <em>Content-type: application/xml</em> and 
  <em>Accept: application/xml</em>
  with the request, the response simply lists: 
  Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p><em>Accept: application/atom+xml</em> does seem to output xml in the raw response. Unfortunately, "application/atom+xml" throws a FormatException in:</p>
  
  <pre><code>request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/atom+xml"));
  </code></pre>