I am trying to load data from XML string into a structure of some sort so once loaded I can then say Data.PropertyName to read the values.
Is the below code the most optimal way of loading the data into the structure?
Obviously calling First() has a memory hit so if you have elements with sub elements will calling First() for each one become an issue?
Thanks
string xml = @"<ROOT>
<ID>1</ID>
<NAME>RF1</NAME>
<STAT>10200</STAT>
<TEST>
<ID>1</ID>
<NAME>BIGUN</NAME>
</TEST>
</ROOT>
";
XElement Data = XElement.Parse(xml);
var Element = (from p in Data.Descendants("ROOT")
select new {
ID = (int)p.Element("ID"),
Test = new {
ID = p.Element("TEST").Descendants("ID").First(),
NAME = p.Element("TEST").Descendants("NAME").First()
},
Stat = p.Element("STAT") }).First();
//Read Element.ID, Element.Test.Name