hi guys I have a mail application. While sending to each recipient I am writing to an XML file named mail.xml. I use the following code:
Dim from As String = txtFrom.Text
Dim txto As String = txtTo.Text
Dim subj As String = txtSubject.Text
Dim body As String = txtBody.Text
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.NewLineOnAttributes = True
Using writer As XmlWriter = XmlWriter.Create("C:\xmlmailfile.xml", settings)
writer.WriteStartDocument()
writer.WriteStartElement("EMail")
writer.WriteStartElement("From")
writer.WriteStartAttribute("From")
writer.WriteValue(from)
writer.WriteEndAttribute()
writer.WriteStartElement("To")
writer.WriteStartAttribute("To")
writer.WriteValue(txto)
writer.WriteEndAttribute()
writer.WriteStartElement("Subject")
writer.WriteStartAttribute("Subject")
writer.WriteValue(subj)
writer.WriteEndAttribute()
writer.WriteStartElement("Body")
writer.WriteStartAttribute("Body")
writer.WriteValue(body)
writer.WriteEndAttribute()
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Flush()
End Using
And the output is:
<?xml version="1.0" encoding="utf-8" ?>
<EMail>
<From From="[email protected]">
<To To="[email protected]">
<Subject Subject="Hi">
<Body Body="Hello" />
</Subject>
</To>
</From>
</EMail>
Here I am not able to append to existing output. Only one "Email" section is being output. I want to add an "Email" section for each recipient. However, in the above code new sections replace previously written ones.
How can I accomplish this?