static void Main(string[] args) { XmlMetadata data = new XmlMetadata() { elemements = new List <Element>() { new Element() { name = "cert", value = "0001" }, new Element() { name = "model", value = "Test" }, new Element() { name = "created", value = "2015-05-21" } } }; XmlSerializer serializer = new XmlSerializer(typeof(XmlMetadata)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("md", "http://example.com/metadata"); StreamWriter writer = new StreamWriter(FILENAME); serializer.Serialize(writer, data, ns); writer.Flush(); writer.Close(); writer.Dispose(); XmlSerializer xs = new XmlSerializer(typeof(XmlMetadata)); XmlTextReader reader = new XmlTextReader(FILENAME); XmlMetadata newData = (XmlMetadata)xs.Deserialize(reader); }
static void Main(string[] args) { XmlMetadata data = new XmlMetadata() { cert = "0001", model = "Test", created = DateTime.Parse("2015-05-21") }; XmlSerializer serializer = new XmlSerializer(typeof(XmlMetadata)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("md", "http://example.com/metadata"); StreamWriter writer = new StreamWriter(FILENAME); serializer.Serialize(writer, data, ns); writer.Flush(); writer.Close(); writer.Dispose(); XmlSerializer xs = new XmlSerializer(typeof(XmlMetadata)); XmlTextReader reader = new XmlTextReader(FILENAME); XmlMetadata newData = (XmlMetadata)xs.Deserialize(reader); }