title: Building XML request with RestSharp
body: <p>I am attempting to work with a REST API using RestSharp and C#.
  The documentation for the API that I am using gives a sample XML request:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;  
  &lt;messages&gt;  
   &lt;accountreference&gt;EX0000000&lt;/accountreference&gt; 
   &lt;from&gt;07700900654&lt;/from&gt;
   &lt;message&gt;  
    &lt;to&gt;07700900123&lt;/to&gt;  
    &lt;type&gt;SMS&lt;/type&gt;  
    &lt;body&gt;Hello Mr Sands.&lt;/body&gt;
   &lt;/message&gt;  
   &lt;message&gt;  
    &lt;to&gt;07700900124&lt;/to&gt;  
    &lt;type&gt;SMS&lt;/type&gt;  
    &lt;body&gt;Hello Mr Mayo.&lt;/body&gt;
   &lt;/message&gt;  
  &lt;/messages&gt;
  </code></pre>
  
  <p>I am struggling to understand how to build the request in the format that they want (multiple elements called "message")</p>
  
  <p>I have created these classes for RestSharp to serialize:</p>
  
  <pre><code>public class messages
  {
      public string accountreference { get; set; }
  
      public string from { get; set; }
  
      public message message { get; set; }
  }
  
  public class message
  {
      public string to { get; set; }
  
      public string body { get; set; }
  }
  </code></pre>
  
  <p>And here is my RestSharp code:</p>
  
  <pre><code>var client = new RestClient("http://api.url.com/v1.0")
                           {
                               Authenticator =
                                   new HttpBasicAuthenticator(
                                   UserName,
                                   Password)
                           };
  
  var request = new RestRequest("theresource", Method.POST) { RequestFormat = DataFormat.Xml };
  
  request.AddBody(
      new messages
          {
              accountreference = Configuration.AccountReference,
              from = Configuration.From,
              message =
                  new message { to = Configuration.Message.To, body = Configuration.Message.Body }
          });
  
  var response = client.Execute(request);
  </code></pre>
  
  <p>This works great when I have only 1 message element, but I don't know how to create multiple message elements without having them nested in an array, which doesn't work with the API.</p>