Please see my comment to the question. The problem is not correctly formulated: there is a top element (root), but there is no one single "top value". You need to explain it. But, don't rush to clarify: you can easily sort it out by yourself. For such a simple problem, I would recommend using
System.Xml.XmlReader
:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader%28v=vs.110%29.aspx[
^].
Don't be confused: this class is abstract, with a hidden constructor, so you need to create an instance, in your case, from the file name, using a static
factory method:
http://msdn.microsoft.com/en-us/library/w8k674bf(v=vs.110).aspx[
^].
Basically, if you need just one value, it will be something like this:
using System.Xml;
string fileName =
using (XmlReader reader = XmlReader(fileName)) {
while(reader.Read())
if (FindOutWhatYouNeed(
reader.NodeType,
reader.HasValue,
reader.ValueType,
reader.Value))
{
break;
}
}
I wrote the call to the method
FindOutWhatYouNeed
just for example, to illustrate the idea: in your simple case, you just wait until the node is the one you expected, using the current
reader
position through the properties I've shown in the sample of the call; you have to write this method yourself, using your criteria which I don't know.
Please see:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.read%28v=vs.110%29.aspx[
^].
[EDIT]
This approach is the fastest possible one, first of all, because you will read only small top portion of a stream.
[END EDIT]
—SA