Reputation: 23
I have hit somewhat of a brick wall with my code.
I'm trying to read a series of XML elements and add there "Inner.text" values as separate items of a combo box. The code is partially working in that it successfully reads the elements values, but instead of adding them as separate items to the combo-box it seems to be concatenating them into one long string! (see code snippet and XML doc below)
VB.net code:
Dim xml_doc As New XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlElement
xml_doc.Load(Start_Point)
nodelist = xml_doc.SelectNodes("scene1/options")
For Each node In nodelist
ComboBox1.Items.Add(node.InnerText())
Next
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<scene1>
<title>Title</title>
<body>
File body text
</body>
<options>
<p1>91</p1>
<p2>45</p2>
<p3>80</p3>
<p4>14</p4>
<p5>85</p5>
</options>
</scene1>
The desired effect is that the combo-box will be populate with the values of all the child nodes of "options". It should have "91" as one item, "45" as another item ... so on. At the moment I get "9145801485" as one item.
This block of code will be used to read multiple different XML files that will follow the same structure but will have a different number of options, so for example this file have 5 options, the next file might have 3 and the one after that 8. so the code needs to be dynamic in that respect.
I have tried changing the "node" variable to an array, however it produces the same result.
Thank you in advance for all that reply, have been going round in circles with this for some time now !
Cheers
Upvotes: 2
Views: 3466
Reputation: 6856
Your code only selects the node options
and returns the sieved inner text (without XML parts).
Try
nodelist = xml_doc.SelectNodes("scene1/options/*")
to select the individual child nodes.
Upvotes: 3