I must read all first level nodes of the root node of large xml file that looks like the following:
<root>
<record n="1"><a/><b/><c/></record>
<record n="2"><a/><b/><c/></record>
<record n="3"><a/><b/><c/></record>
</root>
And my code looks like:
var xml = XDocument.Load(filename);
var firstNode = xml?.Root?.Descendants()?.FirstOrDefault();
var elements = firstNode?.Elements();
I just need to get the first child of the root and all first level descendants of it. This code works fine, but the question is: is it safe to read like this? I guess it does not load all data into memory - only the structure of the xml file?
As I see memory is not increased while debugging. It only explodes if I actually try to see what is in xml
variable.