[ACCEPTED]-How to change XML root name with XML Serialization?-xml-serialization
Accepted answer
In your example, MyTest
is not the root; are you 2 trying to rename the array? I would write 1 a wrapper:
[XmlRoot("NameOfRootElement")]
public class MyWrapper {
private List<MyTest> items = new List<MyTest>();
[XmlElement("NameOfChildElement")]
public List<MyTest> Items { get { return items; } }
}
static void Main() {
MyTest test = new MyTest();
test.Test = "gog";
MyWrapper wrapper = new MyWrapper {
Items = { test }
};
SerializeToXML(wrapper);
}
static public void SerializeToXML(MyWrapper list) {
XmlSerializer serializer = new XmlSerializer(typeof(MyWrapper));
using (TextWriter textWriter = new StreamWriter(@"test.xml")) {
serializer.Serialize(textWriter, list);
textWriter.Close();
}
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.