My XML file looks like this
<?xml version="1.0" encoding="utf-8" ?>
<root>
<mob name="mob1" lvl="5" hp="30" mp="25"/>
<mob name="mob2" lvl="6" hp="50" mp="55"/>
<mob name="mob3" lvl="9" hp="80" mp="85"/>
<mob name="mob4" lvl="11" hp="130" mp="125"/>
</root>
I'm fairly new to programming and working on a program where I can list and keep track of data. What I want to do is have a Combo-box populated with the entries from the "name" attribute, and when you select entry in the combo-box it would pull the Lvl,hp,mp attributes from the same node and put them into some variables to use and display.
The way I had working was using an XML file like this
<?xml version="1.0" encoding="utf-8" ?>
<root>
<moblist list="mob1,mob2,mob3,mob4"/>
<mob0 lvl="5" hp="30" mp="25"/>
<mob1 lvl="6" hp="50" mp="55"/>
<mob2 lvl="9" hp="80" mp="85"/>
<mob3 lvl="11" hp="130" mp="125"/>
</root>
Turning the moblist node list attribute into a list, and using that to populate the combo box. And then having doing something like this :
newindex = cmb_mobs.SelectedIndex
index = "/root/mob" & newindex
Dim doc As XmlDocument = New XmlDocument()
doc.Load("C:/test.xml")
Dim root As XmlNode = doc.DocumentElement
Dim mobs As XmlNode
mobs = root.SelectSingleNode(index)
Dim shw_lvl As String = mobs.Attributes.ItemOf("lvl").InnerText
Dim shw_hp As String = mobs.Attributes.ItemOf("hp").InnerText
Dim shw_mp As String = mobs.Attributes.ItemOf("mp").InnerText
And I would have that go off every time the Combo box had its selected index change.
Question 1:Is there a better way to achieve these results? I am open to changing the xml structure if it can be done better.