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. Select top 5 "rows" in XML -file

Select top 5 "rows" in XML -file

Scheduled Pinned Locked Moved XML / XSL
databasexmlquestion
3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M

    N P 2 Replies Last reply
    0
    • L Lost User

      is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      You can use XPath to contruct a query, then depending on what language you are using to implement this you could (C# exmample):

      public XmlNodeList Search(string input)
      {
      string query = "/mainnode/subnode/[name = " + input.Trim().ToString() + "]";
      XmlDocument doc = new XmlDocument();
      doc.Load("mydata.xml");
      XmlNodeList nodes = doc.SelectNodes(query);
      return nodes;
      }

      Then just iterate through your return XmlNodeList 5 times. I suppose there are other ways to do this, this is just a quick example. -Nick Parker

      1 Reply Last reply
      0
      • L Lost User

        is there any way to make a selection of the top 5 (or any number) rows with certain attributes. I'm used to SQL language and have tried some of the xml features for this too but haven´t seen anything about selecting a certain number of "rows". Anyone who knows? Regards M

        P Offline
        P Offline
        Philip Patrick
        wrote on last edited by
        #3

        Yep, the "pure" xsl solution will be using position() I believe, like this:

        "/store/books[position() <= 5]"

        This will select 5 first books Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer

        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