Results 1 to 4 of 4

Thread: XML Methods

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    7

    Exclamation 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

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    7

    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?

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: XML Methods

    Quote Originally Posted by jmcall10 View Post
    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
  •  



Click Here to Expand Forum to Full Width