It will take some study, but this kind of thing can be done also using
serialization
.
This way you can work with a class which makes coding a lot easier, and serialize the class or
List<>
to
XML
.
See:
[
How to serialize an object to XML by using Visual C#]
An example using a List<>:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
public class Program
{
public static void Main()
{
List<classElement1> listStr = new List<classElement1>();
listStr.Add(new classElement1() { Check = true, Group = "GroupOne" });
listStr.Add(new classElement1() { Check = false, Group = "GroupTwo" });
var x = new XmlSerializer(listStr.GetType());
x.Serialize(Console.Out, listStr);
using (var strWriter = new StringWriter())
{
x.Serialize(strWriter, listStr);
File.WriteAllText("test.xml", strWriter.ToString());
}
Debug.Print("Test Serialization done !");
}
public class classElement1
{
public bool Check;
public string Group = "no group";
public string Key = "no key";
public string Value { get; set; }
}
}