Adding values to XML instead of Overwriting it (XML + VB.NET)

listed in answer

Adding values to XML instead of Overwriting it (XML + VB.NET)
0 votes, 0.00 avg. rating (0% score)

ANSWER:

Ok, how about something like this?

Private Sub MenuItem3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click

    Dim doc as New XmlDocument()
    doc.LoadXml("product.xml")

    Dim root as XmlNode = doc.DocumentElement
    Dim list as XmlNodeList = root.SelectNodes("Table")
    Dim table as XmlNode = list.Item(0)

    table.AppendChild(createNode(doc, ... , ... ))

    Dim writer As New XmlTextWriter(Console.Out)
    writer.Formatting = Formatting.Indented
    doc.WriteTo(writer)
    writer.Flush()

End Sub

Function createNode(XmlDocument doc, ByVal eDate As String, ByVal eSubject As String, ByVal eCategory As String, ByVal eAmount As String, ByVal ePayment As String, ByVal writer As XmlTextWriter) As XmlNode

    Dim element as XmlElement = doc.CreateElement("Expenses")

    Dim dateElement as XmlElement = doc.CreateElement("Date")
    dateElement.InnerText = eDate
    element.AppendChild(dateElement)

    ... similar code for the other sub-elements ...

    Return element

End Function

by Torious from http://stackoverflow.com/questions/10153585