Ive managed so far with this code that amends data to an xml form, but I need to figure out how to remove the bit of code that amends data rather than overwriting it. Ive messed around with the code to see if I could manipulate it myself to get be able to overwrite data, but I havent been able to, so I ask for help.

ElseIf ComboBox1.Text = "Turbine Data" Then
            'start of first combo box code
            Dim filepath As String = My.Application.Info.DirectoryPath & turbdatxml

            If Dir(filepath) <> "" Then

                If (TextBox1.Text.Equals("") Or TextBox2.Text.Equals("") Or TextBox3.Text.Equals("") Or TextBox4.Text.Equals("")) Then

                    MsgBox(val_txt, , inval_title)

                Else
                    Dim ExistingData As New MyDatum

                    Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum))

                    If (File.Exists(filepath)) Then '& Not EOF(1)

                        'Need to find out how to check End of File, and skip this bit of code if file is empty

                        Dim OpenStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open)

                        'Protects existing data, to make a list, rather than overwriting data.
                        ExistingData = Serializer.Deserialize(OpenStream)

                        OpenStream.Close()
                    Else

                        MsgBox(cre05, , err05)

                    End If

                    Dim NewData As New MyData

                    TextBox1.Focus()
                    NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now)
                    NewData.TimeStamp = CDate(TimeString())
                    'find out how to display the date and time seperate, not as a stamp
                    NewData.Gap = gaptext.Text
                    NewData.Diameter = diatext.Text
                    NewData.R2 = TextBox1.Text
                    NewData.VentDiamater = TextBox2.Text
                    NewData.R1 = TextBox3.Text
                    NewData.Height = TextBox4.Text

                    ExistingData.Add(NewData)

                    Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open)
                    ' IO.FileMode.Create or .Open

                    Serializer.Serialize(SaveStream, ExistingData)

                    SaveStream.Close()

                    MsgBox("Data Saved to " & filepath, , _save)

                End If

            Else

                MsgBox(cre05, , err05)

                Dim ExistingData As New MyDatum
                Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum))
                Dim NewData As New MyData
                Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Create)

                TextBox1.Focus()
                NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now)
                NewData.TimeStamp = CDate(TimeString())
                NewData.Gap = gaptext.Text
                NewData.Diameter = diatext.Text
                NewData.R2 = TextBox1.Text
                NewData.VentDiamater = TextBox2.Text
                NewData.R1 = TextBox3.Text
                NewData.Height = TextBox4.Text

                Serializer.Serialize(SaveStream, ExistingData)
                SaveStream.Close()
            End If
            'End of first combo box code

I need to keep with this original code as far as the serializing of the data is concerned, I just need to remove the 'ExistingData' component from the code, and still be able to write data to the xml.

Tamir09,

I need to keep with this original code as far as the serializing of the data is concerned, I just need to remove the 'ExistingData' component from the code, and still be able to write data to the xml.

Do you want to modify the XML document or your source code?

Use DOM.

What is DOM? And how will I be able to apply that to my code?

Document Object Model - a standard to work with XML document. See the System.XML namespace.

Dim doc as New  System.Xml.XmlDocument()
doc.Load("file.xml") 'Load an XML document
...
...
doc.Save("file.xml") 'Save the document

Thanks for the suggestions, but my question is how I can change my current code to allow for overwriting my xml data?

This article has been dead for over six months. Start a new discussion instead.