I've been struggled for many hours to solve this but still didn't find any solution.
I created a xml document using C# code and want to update the content of that xml document when I click a button with a certain event validation. When the xml document was empty it's fine here is the result :
<?xml version="1.0" encoding="utf-8"?>
<Koneksi>
<Nama>Fast Connection</Nama>
<Host>127.0.0.1</Host>
<Username>admin</Username>
<Password>xx</Password>
</Koneksi>
but when I hit the second trigger the xml document was updated to this :
<?xml version="1.0" encoding="utf-8"?>
<Koneksi>
<Nama>Fast Connection</Nama>
<Host>127.0.0.1</Host>
<Username>admin</Username>
<Password>xx</Password>
</Koneksi><?xml version="1.0" encoding="utf-8"?>
<Koneksi>
<Nama>Fast Connection</Nama>
<Host>127.0.0.1</Host>
<Username>admin</Username>
<Password>xx</Password>
</Koneksi>
The problem is why those xml header keep present after the last element.
Here is the C# code :
void createXMLConnection(){
XmlWriterSettings setting = new XmlWriterSettings();
setting.Indent = true;
Stream xmlfile = new FileStream("connection.xml",FileMode.Append);
XmlWriter writer = XmlWriter.Create(xmlfile,setting);
writer.WriteStartDocument();
writer.WriteStartElement("Koneksi");
if(fm2.txtNamaKoneksi.Text==""){
writer.WriteElementString("Nama","Fast Connection");
}else{
writer.WriteElementString("Nama",fm2.txtNamaKoneksi.Text);
}
writer.WriteElementString("Host",txtFTPAddress.Text);
writer.WriteElementString("Username",txtUsername.Text);
writer.WriteElementString("Password",txtPassword.Text);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}Somebody please help me.

1 answers
Well, what you're doing there is successively creating new XML documents and appending them to the same file.
What you need to do is to create an XML document containing just a root element and then append new Koneksi nodes on each button press. Something like this:
answered one year ago by:
17279
0
Wowwww great..it works thank you Mr.vulpes :-)