Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert from dynamic xml to c# object
    primarykey
    data
    text
    <p>I need inputs in converting an dynamic xml to defined c# object model</p> <p>My sample xml is as below :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;Persons&gt; &lt;Person&gt; &lt;Id&gt;10&lt;/Id&gt; &lt;FirstName&gt; Dino &lt;/FirstName&gt; &lt;LastName&gt; Esposito &lt;/LastName&gt; &lt;Addresses&gt; &lt;Address&gt; &lt;AddressType&gt;BillTo&lt;/AddressType&gt; &lt;Street1&gt;&lt;/Street1&gt; &lt;Street2&gt;&lt;/Street2&gt; &lt;Street3&gt;&lt;/Street3&gt; &lt;City&gt;Moscow&lt;/City&gt; &lt;/Address&gt; &lt;Address&gt; &lt;AddressType&gt;ShipTo&lt;/AddressType&gt; &lt;Street1&gt;&lt;/Street1&gt; &lt;Street2&gt;&lt;/Street2&gt; &lt;Street3&gt;&lt;/Street3&gt; &lt;City&gt;Moscow&lt;/City&gt; &lt;/Address&gt; &lt;Address&gt; &lt;AddressType&gt;Contact&lt;/AddressType&gt; &lt;Street1&gt;&lt;/Street1&gt; &lt;Street2&gt;&lt;/Street2&gt; &lt;Street3&gt;&lt;/Street3&gt; &lt;City&gt;Moscow&lt;/City&gt; &lt;/Address&gt; &lt;/Addresses&gt; &lt;/Person&gt; &lt;/Persons&gt; </code></pre> <p>I am expecting the values of this xml to be converted to C# object at run time. I would want an object similar to the following to be defined: My Expected class object C# is as below:</p> <pre><code>public class Person { public int Id { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public IList&lt;Address&gt; Addresses { get; set; } } public class Address { public string AddressType { get; set; } public string Street1 { get; set; } public string Street2 { get; set; } public string Street3 { get; set; } public string City { get; set; } } </code></pre> <p>I went through dynamic and ExpandoObject in C# 4.0, this approach is allowing me to get values dynamically by using keys. I dont know how i can populate these to my datamodel.</p> <p><strong>Note:</strong> I dont want to define this class model structure, this keeps changing over period of time. I am looking for a solution which allows me to get values like DynamicObject.Addresses.Address[0].City.</p> <p>Kindly give your inputs.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload