XML Reader

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
User avatar
Kieken72
VIP - Donator
VIP - Donator
Posts: 231
Joined: Sun May 02, 2010 10:38 am

XML Reader
Kieken72
Hello,
I'm going to learn how to make an easy XML reader:
XML file
Code: Select all
<products>
  <product>
    <id>1</id>
    <name>Ipod Touch 4</name>
    <price>200</price>
    <btw>21</btw>
  </product>
  <product>
    <id>2</id>
    <name>Itunes Store Card €15</name>
    <price>15</price>
    <btw>21</btw>
  </product>
</products
Then first of all make sure u put:
Code: Select all
Imports System.XML
at the top then dim the document and a node:
Code: Select all
Dim XmlDoc As New XmlDocument
        Dim XmlNode As XmlNode
        
Then we are going to load the document:
Code: Select all
XmlDoc.load("Products.xml")
then for example if the form load it must give each Product in a listbox then do:
Code: Select all
For Each XmlNode In XmlDoc.SelectNodes("//product")
ListBox1.Items.Add(XmlNode.SelectSingleNode("name").InnerText
Next)
then if you want more details example like the MMDC6 u can show up a new form and give details:
Code: Select all
XmlNode = XmlDoc.SelectSingleNode("/products/product[name='" & Form1.ListBox1.SelectedItem & "']")
        Label1.Text = XmlNode.SelectSingleNode("id").InnerText
        Label2.Text = XmlNode.SelectSingleNode("name").InnerText
        Label3.Text = XmlNode.SelectSingleNode("price").InnerText & " EUR"
        Label4.Text = XmlNode.SelectSingleNode("btw").InnerText & " %"
Project Source:
20110307-CodenStuff-XMLReader.rar
Greeets Kieken :)
Xml Writer Tutorial
You do not have the required permissions to view the files attached to this post.
1 post Page 1 of 1
Return to “Tutorials”