XML Writer
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.
3 posts
Page 1 of 1
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
You do not have the required permissions to view the files attached to this post.
Last edited by Kieken72 on Wed Mar 09, 2011 2:12 pm, edited 1 time in total.
Not that I didn't understand it, but would you make the code easier to understand? Maybe put some comments? But I thought there was this XMLWriter class to do such things. Just saying.
But good job
But good job
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

oh give me a second

Code: Select all
Like the document this is a the node we will add:
XmlDoc.SelectSingleNode("/products").InnerXml &= "<product><id>" & NumericUpDown1.Value & "</id><name>" & TextBox1.Text & "</name><price>" & TextBox2.Text & "</price><btw>" & ComboBox1.Text & "</btw></product>"
Code: Select all
Then we will putt our values in it so:
<product>
<id>-</id>
<name>-</name>
<price>-</price>
<btw>-</btw>
</product>
Code: Select all
Then put it under the last <product></product>
<product>
<id>" & NumericUpDown1.Value & "</id>
<name>" & TextBox1.Text & "</name>
<price>" & TextBox2.Text & "</price>
<btw>" & ComboBox1.Text & "</btw>
</product>
Code: Select all
and then save XmlDoc.SelectSingleNode("/products").InnerXml &= "<product><id>" & NumericUpDown1.Value & "</id><name>" & TextBox1.Text & "</name><price>" & TextBox2.Text & "</price><btw>" & ComboBox1.Text & "</btw></product>"

Code: Select all
XmlDoc.save
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023