title: API - XML doesn't get correct format (WebAPI Controller)
body: <p>I'm struggling with my XML output.</p>
  <p>I have a method that takes in a <code>PersonalID</code> and shall return <code>address</code>, as well as some additional information from it.</p>
  <p><strong>Execute a API request and put separate values in string variables</strong></p>
  <pre><code>public string ReturnRegistered(String personalID)
  {
                  string apiurl = apiadress + personalID;
                  WebRequest request = WebRequest.Create(apiurl);
  
                  //TILLÄGG FÖR AUTHENTICATION
                  request.PreAuthenticate = true;
                  request.Credentials = new NetworkCredential(user, pass);
                  //TILLÄGG FÖR AUTHENTICATION
  
                  WebResponse respons = request.GetResponse();
                  Stream dataStream = respons.GetResponseStream();
  
                  //OBJEKT
                  XmlSerializer serializer = new XmlSerializer(typeof(List&lt;PrimaryContact&gt;), new XmlRootAttribute(&quot;QueueSlot&quot;));
                  var input = (List&lt;PrimaryContact&gt;)serializer.Deserialize(dataStream);
  
               
                  string firstname = input[0].firstname;
                  string lastname = input[0].lastname;
                  string postalAddress = input[0].postalAddress;
                  string zipCode = input[0].zipCode;
                  string address = input[0].address;   
  
       //FÖR ATT KUNNA TA FRAM ENDAST ETT ATTRIBUT BEHÖVER MAN GÖRA OM HELA WEBREQUESTEN OCH NERÅT
                  WebRequest request2 = WebRequest.Create(apiurl);
  
                  //TILLÄGG FÖR AUTHENTICATION
                  request2.PreAuthenticate = true;
                  request2.Credentials = new NetworkCredential(user, pass);
                  //TILLÄGG FÖR AUTHENTICATION
  
                  WebResponse respons2 = request2.GetResponse();
                  Stream dataStream2 = respons2.GetResponseStream();
  
                  //ENVÄRDE
                  XmlDocument doc = new XmlDocument();
                  doc.Load(dataStream2);
                  XmlNodeList elemList2 = doc.GetElementsByTagName(&quot;lastPaymentDate&quot;);
                  string lastPaymentDate = elemList2[0].InnerText;            
  
  
  String returnvalue = &quot;&lt;Fields&gt;&lt;Field&gt;&lt;Name&gt;lastPaymentDate&lt;/Name&gt;&lt;Value&gt;&quot; + lastPaymentDate + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;Field&gt;&lt;Name&gt;Firstname&lt;/Name&gt;&lt;Value&gt;&quot;+ firstname + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;Field&gt;&lt;Name&gt;Lastname&lt;/Name&gt;&lt;Value&gt;&quot;+ lastname + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;Field&gt;&lt;Name&gt;Adress&lt;/Name&gt;&lt;Value&gt;&quot;+ address + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;Field&gt;&lt;Name&gt;ZipCode&lt;/Name&gt;&lt;Value&gt;&quot;+ zipCode + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;Field&gt;&lt;Name&gt;PostalAdress&lt;/Name&gt;&lt;Value&gt;&quot;+ postalAddress + &quot;&lt;/Value&gt;&lt;/Field&gt;&lt;/Fields&gt;&quot;;
  *//I have tryed start with &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; but no different.*
  
  return returnvalue;
  }
  </code></pre>
  <p>Then my API uses that method and shall return a <code>XmlElement</code>. <em>&quot;I have read on this site that I don't need to specify which element is Root and child and so on when using LoadXml&quot;</em></p>
  <p><strong>Controller</strong>:</p>
  <pre><code>public XmlElement Get(string id)
          {
              Models.TomtkoRegistered tomtko = new Models.TomtkoRegistered();
              String returnvalue = tomtko.ReturnRegistered(id);     
                  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(returnvalue);
                  XmlElement root = doc.DocumentElement;
              return root;
          }
  </code></pre>
  <p>If I print it to file I get it to work, but I don't know how to make the  XML in the correct format for a webAPI so the format is usable by the receiver of my webAPI.</p>
  <p><strong>But</strong> when I use the API in Firefox or Chrome
  <a href="https://i.stack.imgur.com/jbSJj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jbSJj.png" alt="enter image description here" /></a></p>
  <p>It &quot;looks&quot; fine but when I look at the page source and try to use it, or add it to Notepad++ then everything is just on one line and not formatted or structured.</p>
  <p><a href="https://i.stack.imgur.com/drVwm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/drVwm.png" alt="enter image description here" /></a>
  What is wrong??</p>
  <p>Can I force the Content-Type to be &quot;text/xml&quot; in some way?
  Did I use the wrong return type?
  Is it missing some other code?</p>
  <p>When a friend used it in <code>Postman</code> some action value was default set to anyvalue (*) in some way not 100% what it was but when he put it in XML it works. But how to I make the receiver understand from the beginning that it shall be XML if <code>XmlElement</code> doesn't do the trick?</p>