Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Getting maximum id

Getting maximum id

Scheduled Pinned Locked Moved XML / XSL
csharpxmlhtmlcomquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    N a v a n e e t h
    wrote on last edited by
    #1

    <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

    L H 2 Replies Last reply
    0
    • N N a v a n e e t h

      <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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • L led mike

        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

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • N N a v a n e e t h

          <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

          H Offline
          H Offline
          henningbenk
          wrote on last edited by
          #4

          Try this one XPath-Expression: child[not(../child/@id > @id)]/@id

          1 Reply Last reply
          0
          • N N a v a n e e t h

            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

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups