XML Writer
Posted: Wed Mar 09, 2011 1:31 pm
Hello,
I'm going to learn how to make an easy XML Writer ( It will add new nodes)
XML file
I added 4 labels: ID,Product name, Price and Btw , a numeric Up and Down , 2 textboxes and a combobox ( items: 0,6,12,21)
then a button and then the code of the button:)

then dim the document:

Source: XML Reader Tutorial
I'm going to learn how to make an easy XML Writer ( It will add new nodes)
XML file
Code: Select all
Then first of all make sure u put:
<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
Code: Select all
at the top Imports System.XML
I added 4 labels: ID,Product name, Price and Btw , a numeric Up and Down , 2 textboxes and a combobox ( items: 0,6,12,21)
then a button and then the code of the button:)

then dim the document:
Code: Select all
Then we are going to load the document:
Dim XmlDoc As New XmlDocument
Code: Select all
then the writing XmlDoc.load("Products.xml")

Code: Select all
and this is it XmlDoc.SelectSingleNode("/products").InnerXml &= "<product><id>" & NumericUpDown1.Value & "</id><name>" & TextBox1.Text & "</name><price>" & TextBox2.Text & "</price><btw>" & ComboBox1.Text & "</btw></product>"
'selects the first node were all the product nodes are in and adds to the bottom a new node with innerxml.
XmlDoc.Save("Products.xml")
'saves document
MsgBox("Added", MsgBoxStyle.Information, "Info")
'show msgbox completed
NumericUpDown1.Value = (NumericUpDown1.Value + 1)
TextBox1.Clear()
TextBox2.Clear()
ComboBox1.Text = ""
'clears inputs ;)

Source: XML Reader Tutorial