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