Reputation: 2014
I have the following vb.net code and XML file. What I am trying to achieve is to add each TTN value to the ComboBox
but I get no result. No errors just nothing. I have checked the XML file and it passes as error free. Could someone explain what's going wrong.
Dim xml_doc As New XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlElement
xml_doc.Load(IO.Directory.GetCurrentDirectory & "\Stock.xml")
nodelist = xml_doc.SelectNodes("Compelation/Data/TTN")
For Each node In nodelist
ComboBox1.Items.Add(node.InnerText())
Next
XML file:
<COMPELATION>
<Data>
<TTN>FD33</TTN>
<FJQ>3</FJQ>
<TTH>257,85</TTH>
<TTW>290</TTW>
<FCT>SC1-CON</FCT>
<MTD>50</MTD>
<MTT>2</MTT>
<DVB>20</DVB>
<TVB>2</TVB>
<DTP>12</DTP>
<MAT>6082 T6</MAT>
<TSW>0,044</TSW>
</Data>
<Data>
<TTN>FD34</TTN>
<FJQ>4</FJQ>
<TTH>290</TTH>
<TTW>290</TTW>
<FCT>SC1-CON</FCT>
<MTD>50</MTD>
<MTT>2</MTT>
<DVB>20</DVB>
<TVB>2</TVB>
<DTP>12</DTP>
<MAT>6082 T6</MAT>
<TSW>0,058</TSW>
</Data>
</COMPELATION>
Upvotes: 0
Views: 163
Reputation: 11773
How about this:
Dim doc As XElement
XElement.Load(IO.Path.Combine(IO.Directory.GetCurrentDirectory, "Stock.xml"))
Dim ttnNodes As IEnumerable(Of String) = From xe As XElement In doc.<Data>.<TTN>
Select xe.Value
ComboBox1.DataSource = ttnNodes.ToList
To test this I used this instead of loading the file
doc = <COMPELATION>
<Data>
<TTN>FD33</TTN>
<FJQ>3</FJQ>
<TTH>257,85</TTH>
<TTW>290</TTW>
<FCT>SC1-CON</FCT>
<MTD>50</MTD>
<MTT>2</MTT>
<DVB>20</DVB>
<TVB>2</TVB>
<DTP>12</DTP>
<MAT>6082 T6</MAT>
<TSW>0,044</TSW>
</Data>
<Data>
<TTN>FD34</TTN>
<FJQ>4</FJQ>
<TTH>290</TTH>
<TTW>290</TTW>
<FCT>SC1-CON</FCT>
<MTD>50</MTD>
<MTT>2</MTT>
<DVB>20</DVB>
<TVB>2</TVB>
<DTP>12</DTP>
<MAT>6082 T6</MAT>
<TSW>0,058</TSW>
</Data>
</COMPELATION>
Upvotes: 1
Reputation: 2370
This will also work for you:
nodelist = xml_doc.SelectNodes("COMPELATION/Data/TTN")
Upvotes: 1