|
-
Nov 5th, 2012, 08:45 PM
#1
Thread Starter
New Member
XML Methods
Hi, I am not the best at visual basic so please be patient 
I have some code that works fine however I get some warnings saying the code will no longer be supported or used in the future.
The simple nuts and bolts is I read in an XML file, and my code allows me to edit, or add (havent worked out the delete yet haha).
So before I code any more I would rather bring it up to current practice. Can someone help by means of sample code etc?
Here is my current code:
Code:
Imports System.Xml
Public Class Form1
Public Sub Loadsample()
Dim data As New XmlDataDocument
Dim se As New DataSet("samplelists")
data.DataSet.ReadXml(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
se = data.DataSet
DataGridView1.DataSource = se.DefaultViewManager
DataGridView1.DataMember = "Server"
DataGridView1.Columns.Item(0).HeaderText = "Server Name"
DataGridView1.Columns.Item(1).HeaderText = "Server URL"
DataGridView1.Columns.Item(2).Visible = False
DataGridView1.Columns.Item(3).Visible = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Loadsample()
End Sub
Private Sub DATA_Click() Handles DataGridView1.Click
Dim da As New XmlDataDocument
da.Load(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
Dim path As String = "/samplelists/server/serverName[text()='" & DataGridView1.CurrentRow.Cells(0).Value.ToString & "']"
Dim path2 As String = "/samplelists/server/serverURL[text()='" & DataGridView1.CurrentRow.Cells(1).Value.ToString & "']"
Dim node As XmlNode = da.SelectSingleNode(path)
Dim node2 As XmlNode = da.SelectSingleNode(path2)
TextBox3.Text = node.InnerText
TextBox4.Text = node2.InnerText
End Sub
Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
Dim doc As New XmlDocument
doc.Load(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
Dim ele As XmlNode = doc.DocumentElement
Dim chi As XmlElement = doc.CreateElement("server")
Dim chi1 As XmlElement = doc.CreateElement("serverName")
Dim chi2 As XmlElement = doc.CreateElement("serverURL")
chi.SetAttribute("dateAdded", Date.Today.ToString)
chi.SetAttribute("addedBy", "user")
chi1.InnerText = TextBox1.Text
chi2.InnerText = TextBox2.Text
chi.AppendChild(chi1)
chi.AppendChild(chi2)
ele.AppendChild(chi)
doc.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
TextBox1.Text = ""
TextBox2.Text = ""
Loadsample()
MsgBox("Data Added")
End Sub
Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Update.Click
Dim da As New XmlDataDocument
da.Load(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
Dim path As String = "/samplelists/server/serverName[text()='" & DataGridView1.CurrentRow.Cells(0).Value.ToString & "']"
Dim path2 As String = "/samplelists/server/serverURL[text()='" & DataGridView1.CurrentRow.Cells(1).Value.ToString & "']"
Dim node As XmlNode = da.SelectSingleNode(path)
Dim node2 As XmlNode = da.SelectSingleNode(path2)
node.InnerText = TextBox3.Text
node2.InnerText = TextBox4.Text
da.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "/sample.xml")
Loadsample()
End Sub
Private Sub Quit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Quit.Click
End
End Sub
End Class
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|