title: How to serialize Anonymous-typed Objects to XML?
body: <p>Is there any possible way to serialize dynamically created object to an xml string?</p>
  
  <pre><code>var foobar = new { foo = "bar" };
  string xml = ConvertToXMLString(foobar);
  //xml should be something like : 
  //&lt;foo&gt;bar&lt;/foo&gt;
  </code></pre>
  
  <p>I was able to take a look at XMLSerializer and DataContractSerializer but XMLSerializer requires the object type while DataContractSerializer requires attribute on the properties that needs to be serialized.</p>
  
  <p>Out of desperation, I converted the object to JSON first and from JSON converted it to XML. </p>
  
  <pre><code>var foobar = new { foo = "bar" };
  JavaScriptSerializer js = new JavaScriptSerializer();
  jsonString = js.Serialize(values);
  //Json.NET at http://json.codeplex.com/
  XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonString);
  </code></pre>