using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace EE_Q28736062
{
class Program
{
static void Main(string[] args)
{
ETestSerializer test = new ETestSerializer();
test.GLEntries.Add(new GLEntry() { ID = 1, Name = "First" });
test.GenerateXml("test.xml");
}
}
[Serializable(), XmlRoot("eTest")]
public class ETestSerializer
{
private readonly List<GLEntry> fGLEntries = new List<GLEntry>();
[XmlAttribute(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string noNamespaceSchemaLocation = "eTest-Schema.xsd";
[XmlElement()]
public List<GLEntry> GLEntries { get { return fGLEntries; } }
public void GenerateXml(string fileName)
{
GenerateXml(new FileInfo(fileName));
}
public void GenerateXml(FileInfo file)
{
XmlSerializer serializer = new XmlSerializer(GetType());
using (TextWriter stream = new StreamWriter(file.FullName))
{
XmlSerializerNamespaces spaces = new XmlSerializerNamespaces();
spaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
serializer.Serialize(stream, this, spaces);
}
}
}
[Serializable()]
public class GLEntry
{
public int ID { get; set; }
public string Name { get; set; }
}
}
Which now produces the following output -
Open in new window
Which produces the following xml file -