given the following code [Serializable] public class check { public check() { //int_array = new List<int>(); string_array = new List<string>(); } [XmlArray("string_array",Order=1)] [XmlArrayItem("string_element",typeof(string))] public List<string> string_array; //[XmlArray("int_array")] //[XmlArrayItem("int_element")] //public List<int> int_array; public void write_to_xml(string path) { XmlSerializer serailizer = new XmlSerializer(typeof(check)); TextWriter writer = new StreamWriter(path); serailizer.Serialize(writer, this); writer.Close(); } static void Main() { //check class check c = new check(); c.string_array.AddRange(new string[] { "string1", "string2", "string3" }); c.write_to_xml(@"E:\check.xml"); } }
<?xml version="1.0" encoding="utf-8"?> <check xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <string_array> <string_element>string1</string_element> <string_element>string2</string_element> <string_element>string3</string_element> </string_array> </check>
[XmlArray("int_array", Order=2)] [XmlArrayItem("int_element", typeof(int))] public List<int> int_array;</int>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)