Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

XMLWriter I want multiple nodes or tags in a single xml file but my code overwrites

$
0
0
Hey all, I did a search on XMLWrtier here and couldn't find what I am looking for and I am sure it is a simple thing as I see it done all of the time but I am knew to writing to XML I usually use Databases.

My question is how do I append the xml file with new tags? here is what I have writen to the XML file.
Code:

<?xml version="1.0" encoding="UTF-8"?>

<!--XML Database-->
-<AccountData>
<AccountName>Tim</AccountName>
<HourlyRate>11.00</HourlyRate>
</AccountData>


What I want is to append this with another record. like this but every time I write to the xml it overwrites the fist tag.
Code:

-<AccountData>
<AccountName>Tim</AccountName>
<HourlyRate>11.00</HourlyRate>
<AccountName>Jack</AccountName>
<HourlyRate>15.00</HourlyRate>
</AccountData>

Code:

Private Sub btnAccountSave_Click(sender As Object, e As EventArgs) Handles btnAccountSave.Click
        'declare our xmlwritersettings object
        Dim settings As New XmlWriterSettings()
        Dim XMLWrite As XmlWriter = XmlWriter.Create("AccountSettings.xml", settings)

        With XMLWrite
            .WriteStartDocument()
            .WriteComment("XML Database")
            .WriteStartElement("AccountData")
            'Start the account tags
            .WriteStartElement("AccountName")
            .WriteString(cboAccountName.Text)
            .WriteEndElement()
            .WriteStartElement("HourlyRate")
            .WriteString(txtHourlyRate.Text)
            .WriteEndElement()
            .WriteEndDocument()
            .Close()
            Me.Close()
        End With
    End Sub


Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>