title: Converting XML to a dynamic C# object
body: <p>I've used the following C# code to convert a string of JSON data to a dynamic object using the JSON.Net framework:</p>
  
  <pre><code>// Creates a dynamic .Net object representing the JSON data
  var ProductDB = JsonConvert.DeserializeObject&lt;dynamic&gt;(JsonData);
  </code></pre>
  
  <p>Once converted, I can access the elements directly using code like this:</p>
  
  <pre><code>// Variables to be used
  string ProductID;
  string ProductType;
  int ProductQty;
  
  // Loop through each of the products
  foreach (dynamic product in ProductDB.products)
  {
      ProductID = product.id;
      ProductType = product.type;
      ProductQty = product.qty;
  }
  </code></pre>
  
  <p>Is there anything similar to this for working with XML data? I could just use JSON.net to convert my XML to JSON and then re-use the code above, but that feels like cheating.</p>
  
  <p>Thanks.</p>