I have an XML file with the following structure:
<doc>
<rootelement>
<childelement id="0" />
<childelement id="1" />
.
.
</rootelement>
</doc>
I want to find the highest numeric value of the id
attribute
The idea I have in mind is something like:
int highest = -1;
foreach(var node in xmldoc.SelectNodes("//doc/rootelement/childelement"))
{
highest = Math.Max(GetID(node), highest);
}
where GetID(XMLNode)
would retrieve the value of the attribute of the current node.
Is there a more compact (or more efficient) XPath expression to do that?