Ich habe jetzt zum Schreiben folgenden Code eingesetzt:
//XML-Datei öffnen
XmlTextWriter xw = new XmlTextWriter(xmlFile, System.Text.Encoding.UTF8);
//Xml-Datei soll formattiert werden
xw.Formatting = Formatting.Indented;
//Head
xw.WriteStartDocument();
//RootElement
xw.WriteStartElement("configurations");
//Irgendwas schreiben
xw.WriteElementString("ip", textBox1.Text);
xw.WriteElementString("db", textBox2.Text);
xw.WriteElementString("user", textBox3.Text);
xw.WriteElementString("password", textBox4.Text);
xw.WriteElementString("path", "C:\bilder");
//RootElement abschliessen
xw.WriteEndElement();
//Dokument abschliessen
xw.WriteEndDocument();
//Xml-Datei schliessen
xw.Close();
Ergebnis:
<?xml version="1.0" encoding="utf-8" ?>
- <configurations>
<ip>127.0.0.1</ip>
<db>test</db>
<user>root</user>
<password />
<path>C:\bilder</path>
</configurations>
Aber...:
Wie bekommt man folgende Unterteilung hin nach "mySQL" und "images"?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<mySQL>
<ip>127.0.0.1</ip>
<db>myShop</db>
<user>root</user>
<password></password>
</mySQL>
<images>
<path>C:\bilder</path>
</images>
</configuration>
MfG
Jens