Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with XML documents and loops?
#2
To read the XML file you are going to want to use an XMLTextReader object.

Specifically, let's break down your task here.
1) Read the XML document.
The first thing you want to do is create a XML Document variable, so, let's say that your XML Document is stored in "doc.xml".

First, let's create the variable:
[code2=vbnet]Dim xml_doc As New Xml.XmlDocument[/code2]

Now we need to assign the xml_doc variable to the XML document on the disk:
[code2=vbnet]xml_doc.Load("doc.xml")[/code2]

Now that the XML variable is setup, let's go about your next problems.
* Create a ToolStripButton for each childnode in the XMLDocument with the text <name>
Well, this is relatively simple with our current setup. So let's scroll through all the childnodes and create a ToolStripButton for them all!
[code2=vbnet]For Each node As Xml.XmlNode In xml_doc.ChildNodes
Dim button As New ToolStripButton
button.Text = node.Attributes("name").InnerText
button.Tag = node.Attributes("URL").InnerText
AddHandler button.Click, AddressOf TSButtonClick
Next[/code2]

In this snippet of code we also store the URL that the button links to inside the buttons "tag" property, and add a handler that links it to another method when the button is clicked. So, we just need to create the body of that method:
[code2=vbnet]Sub TSButtonClick(sender As Object, e As System.EventArgs)
Dim button As ToolStripButton = CType(sender, ToolStripButton)
Process.Start(button.Tag)
End Sub[/code2]

And voila! We have a working program (I hope). I have not tested it, so please correct me if it doesn't work.
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Help with XML documents and loops? - by Derek275 - 11-06-2012, 05:11 AM
Re: Help with XML documents and loops? - by brandonio21_phpbb3_import2 - 11-06-2012, 09:48 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)