|
-
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
-
Nov 6th, 2012, 07:25 AM
#2
Re: XML Methods
Things to consider, how long will the app stay in production? If many years than consider using current methods and if not don't worry about it.
Will you be upgrading Visual Studio during the life span of the app, if so and you find the methods giving warnings now turn out to not work then upgrade the methods at that time.
Here are some current methods using LINQ you might consider
http://msdn.microsoft.com/en-us/vstudio/bb688087
-
Nov 6th, 2012, 06:24 PM
#3
Thread Starter
New Member
Re: XML Methods
Ok I did actually ponder some of this before posting. I have some questions, which will no doubt sound stupid.
If I continue with my existing methods and then have a completed "app". So I have my .exe file that I will no longer update. If my methods expire will my .exe file no longer work? or is it only if I go to compile it again?
Basically if I make the .exe the now will it run forever?
-
Nov 6th, 2012, 06:34 PM
#4
Re: XML Methods
 Originally Posted by jmcall10
If I continue with my existing methods and then have a completed "app". So I have my .exe file that I will no longer update. If my methods expire will my .exe file no longer work? or is it only if I go to compile it again?
Basically if I make the .exe the now will it run forever?
In this case your app will work as is since it is compiled to work with a specific Framework on the OS it was designed for.
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
|