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. ForEach reading only the last node only

ForEach reading only the last node only

Scheduled Pinned Locked Moved XML / XSL
xmlquestionannouncement
3 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
    albchinsh
    wrote on last edited by
    #1

    HI <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Probedata>    <Data>       <Key>10</Key>       <Cmd>1</Cmd>       <Coil1>2</Coil1>       <Coil2>0</Coil2>       <Program>False</Program>       <Line>0</Line>    </Data>    <Data>       <Key>20</Key>       <Cmd>2</Cmd>       <Coil1>4</Coil1>       <Coil2>0</Coil2>       <Program>False</Program>       <Line>4</Line>    </Data> <Data>       <Key>30</Key>       <Cmd>3</Cmd>       <Coil1>2</Coil1>       <Coil2>5</Coil2>       <Program>False</Program>       <Line>1</Line>    </Data> </Probedata> This is my XML file and the program part to read xml below xmlProbe.Load(probe.xml) Dim xmlNodeList As Xml.XmlNodeList xmlNodeList = .xmlProbe.SelectNode("Probedata")                         For Each j As Xml.XmlNode In xmlNodeList                               key = CInt(xmlPNode.ChildNodes(0).InnerText)                               prg.Cmd = CInt(xmlPNode.ChildNodes(1).InnerText)                               prg.Coil1 = CSng(xmlPNode.ChildNodes(2).InnerText)                               prg.Coil2 = CSng(xmlPNode.ChildNodes(3).InnerText)                               prg.Program = CBool(xmlPNode.ChildNodes(4).InnerText)

    A 1 Reply Last reply
    0
    • A albchinsh

      HI <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Probedata>    <Data>       <Key>10</Key>       <Cmd>1</Cmd>       <Coil1>2</Coil1>       <Coil2>0</Coil2>       <Program>False</Program>       <Line>0</Line>    </Data>    <Data>       <Key>20</Key>       <Cmd>2</Cmd>       <Coil1>4</Coil1>       <Coil2>0</Coil2>       <Program>False</Program>       <Line>4</Line>    </Data> <Data>       <Key>30</Key>       <Cmd>3</Cmd>       <Coil1>2</Coil1>       <Coil2>5</Coil2>       <Program>False</Program>       <Line>1</Line>    </Data> </Probedata> This is my XML file and the program part to read xml below xmlProbe.Load(probe.xml) Dim xmlNodeList As Xml.XmlNodeList xmlNodeList = .xmlProbe.SelectNode("Probedata")                         For Each j As Xml.XmlNode In xmlNodeList                               key = CInt(xmlPNode.ChildNodes(0).InnerText)                               prg.Cmd = CInt(xmlPNode.ChildNodes(1).InnerText)                               prg.Coil1 = CSng(xmlPNode.ChildNodes(2).InnerText)                               prg.Coil2 = CSng(xmlPNode.ChildNodes(3).InnerText)                               prg.Program = CBool(xmlPNode.ChildNodes(4).InnerText)

      A Offline
      A Offline
      Adam Maras
      wrote on last edited by
      #2

      It looks like you're referencing some other variable in your loop body, as opposed to your iterator variable. Shouldn't, for example, the first statement in your loop be:

      key = CInt(j.ChildNodes(0).InnerText)

      A 1 Reply Last reply
      0
      • A Adam Maras

        It looks like you're referencing some other variable in your loop body, as opposed to your iterator variable. Shouldn't, for example, the first statement in your loop be:

        key = CInt(j.ChildNodes(0).InnerText)

        A Offline
        A Offline
        albchinsh
        wrote on last edited by
        #3

        Thanks, it works

        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