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. Looping through XmlNodeList

Looping through XmlNodeList

Scheduled Pinned Locked Moved XML / XSL
xmlhelpquestion
2 Posts 2 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.
  • A Offline
    A Offline
    Abbas82
    wrote on last edited by
    #1

    Hi, I have the following code, which picks up 43 different nodes from my XML document XmlNodeList amortNodes = amortDoc.SelectNodes("// TValueAmortizationSchedule/AmortizationLine"); each node looks like this: 8 09/01/2006 100000000 0 0 0 0 100000000 100000000 13 Now I am trying to loop through the node list to get get the nodes with AmortizationLineType = 8 foreach (XmlNode amortNode in amortNodes) { amortType = amortNode.SelectSingleNode("//AmortizationLine/ AmortizationLineType").InnerText; if (amortType.Equals("8")) { count++; ........... } } Now I know from my debugging, that not all 43 nodes fulfil this criteria (ie amortType=8). However, when I run this application, the amortType always comes back as 8 (which is the value on only the first node), which seems to tell me it is not picking up the values after that? Any ideas? Thanks for your help.

    S 1 Reply Last reply
    0
    • A Abbas82

      Hi, I have the following code, which picks up 43 different nodes from my XML document XmlNodeList amortNodes = amortDoc.SelectNodes("// TValueAmortizationSchedule/AmortizationLine"); each node looks like this: 8 09/01/2006 100000000 0 0 0 0 100000000 100000000 13 Now I am trying to loop through the node list to get get the nodes with AmortizationLineType = 8 foreach (XmlNode amortNode in amortNodes) { amortType = amortNode.SelectSingleNode("//AmortizationLine/ AmortizationLineType").InnerText; if (amortType.Equals("8")) { count++; ........... } } Now I know from my debugging, that not all 43 nodes fulfil this criteria (ie amortType=8). However, when I run this application, the amortType always comes back as 8 (which is the value on only the first node), which seems to tell me it is not picking up the values after that? Any ideas? Thanks for your help.

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      The problem is the XPath expression passed to the SelectSingleNode method. The double slash at the beginning causes the selection of all nodes in the document from the current node that match the selection no matter where they are, so you're always selecting the first of the AmortizationLineType elements of all AmortizationLine elements. Try using the following XPath expression amortNode.SelectSingleNode("./AmortizationLineType") instead.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      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