I have an array of objects and I want to pass them into a XML file. The Ojects lack of an attribute ID, in fact the form of the array is:
var people = new[]{
new {Name="James", Age="22", Company="FF"},
new {Name="Susan", Age="31", Company="PK"},
new {Name="Peter", Age="24", Company="TF"},
}
Is there any way to pass them in an xml file, granting to each one of them an ID starting from 1 and increased by 1 for each Object?
The desired form of the xml elemnts should look like:
<People>
<Person ID="1">
<Name>James</Name>
<Age>22</Age>
<Company>FF</Company>
....
</People>
It would be ideal if the solution would constist of one only LINQ query.
1 Answer