Getting maximum id
-
<root>
<child id="1">
<child id="2">
</root>I have above XML file. I need to find out maximum value of the "id" attribute. I have done by getting all nodes and iterating through each one. I tried XPath also, but it don't have any method to find maximum value. Is there any other method to do this ? This XML file may have thousands of
child
nodes.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
<root>
<child id="1">
<child id="2">
</root>I have above XML file. I need to find out maximum value of the "id" attribute. I have done by getting all nodes and iterating through each one. I tried XPath also, but it don't have any method to find maximum value. Is there any other method to do this ? This XML file may have thousands of
child
nodes.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
N a v a n e e t h wrote:
I have done by getting all nodes and iterating through each one.
Is there a problem with that?
led mike
led mike wrote:
Is there a problem with that?
:) Nope. It works well. But is there any other alternative for doing this ? As I will have many nodes, this method may be performance costly.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
<root>
<child id="1">
<child id="2">
</root>I have above XML file. I need to find out maximum value of the "id" attribute. I have done by getting all nodes and iterating through each one. I tried XPath also, but it don't have any method to find maximum value. Is there any other method to do this ? This XML file may have thousands of
child
nodes.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
Try this one XPath-Expression: child[not(../child/@id > @id)]/@id
-
led mike wrote:
Is there a problem with that?
:) Nope. It works well. But is there any other alternative for doing this ? As I will have many nodes, this method may be performance costly.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
N a v a n e e t h wrote:
It works well. But is there any other alternative for doing this ? As I will have many nodes, this method may be performance costly.
"Premature optimization is the root of all evil (or at least most of it) in programming."[^] Source: Donald Knuth, "Computer Programming as an Art" 1974 Turing Award lecture
led mike