1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication
{
public class Program
{
[Serializable]
public class Profil
{
[XmlAttribute]
public string id;
public bool option1;
public bool option2;
}
static void Main(string[] args)
{
Profil p = new Profil();
p.id = "ABC123";
p.option1 = true;
p.option2 = false;
List<Profil> liste = new List<Profil>();
liste.Add(p);
liste.Add(p);
liste.Add(p);
XmlSerializer serializer = new XmlSerializer(typeof(List<Profil>), new XmlRootAttribute("root"));
using (MemoryStream mem = new MemoryStream())
{
serializer.Serialize(mem, liste);
using (FileStream fs = new FileStream("C:\\temp\\test.xml", FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
sw.Write(Encoding.UTF8.GetString(mem.ToArray()));
}
}
}
Console.WriteLine("Done. Press a key.");
Console.ReadLine();
}
}
} |