Euzinho Dassilva Advanced Cheater
Reputation: 0
Joined: 08 Sep 2007 Posts: 62
|
Posted: Sat Oct 13, 2007 7:16 am Post subject: Continuing with Combobox |
|
|
Hi
In this topic I post a problem to read a XML file for my Trainer
Searching a lot (and studying too) I finally solve the problem using XPath.
The Beta tests was a success, but what I really want to do with XML Data no.
This my new code, in a combobox Sub:
| Code: | Private Sub listTowns_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listTowns.SelectedValueChanged
Dim XmlDocument As XmlDocument = New XmlDocument
Select Case Me.listTowns.SelectedItem
Case "Falconreach"
XmlDocument.Load(My.Computer.FileSystem.CurrentDirectory & "\XML\Shop\Falconreach\NormalShop.xml")
End Select
Dim Navigator As XPathNavigator = XmlDocument.CreateNavigator
Dim Expression As XPathExpression = Navigator.Compile("//item")
Dim Nodes As XPathNodeIterator = Navigator.Select(Expression)
Select Case Me.listTowns.SelectedItem
Case "Falconreach"
While Nodes.MoveNext
'Removing Previous Value (if exists)
Me.listNormalShops.Items.Clear()
'Nodes.Current.MoveToChild("ID", "")
'Me.xmlContent.AppendText("Shop ID: " & Nodes.Current.Value & Environment.NewLine)
'Nodes.Current.MoveToParent()
Nodes.Current.MoveToChild("name", "")
'Error: Only add the last item of XML file
Me.listNormalShops.Items.Add(Nodes.Current.Value)
'Nodes.Current.MoveToParent()
Nodes.Current.MoveToParent()
End While
End Select
End Sub |
The XML file (modified) is:
| Code: | <?xml version="1.0" encoding="utf-8" ?>
<Shop>
<item>
<ID>1</ID>
<name>Yulgar's Shop</name>
</item>
<item>
<ID>2</ID>
<name>The Inn Shop</name>
</item>
<item>
<ID>3</ID>
<name>Cysero Shop</name>
</item>
</Shop> |
Note: I post only some items of XML file
Look the line when a comment says: Error:...
The tutorial that I read to explain XPath, write the result in a TextBox field. And works fine.
But, now I need to list the values (the shop names) in a combobox and Nodes.Current.Value only returns me the last name of <item></item> tags
I tried to use AddRange method but don't works to.
Anyone can help me?
Thanks a lot
|
|