Page 1 of 1

XML Reader

Posted: Mon Mar 07, 2011 10:00 am
by 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