C# Changing the element names of items in a list when serializing/deserializing XML -


i have class defined below:

[xmlroot("classname")] public class classname_0 {     //stuff... } 

i create list of classname_0 such:

var mylistinstance= new list<classname_0>(); 

this code use serialize:

var ser = new xmlserializer(typeof(list<classname_0>)); ser.serialize(awriterstream, mylistinstance); 

this code use deserialize:

var ser = new xmlserializer(typeof(list<classname_0>)); var wrapper = ser.deserialize(new stringreader(xml)); 

if serialize xml, resulting xml looks below:

<?xml version="1.0" encoding="utf-8"?> <arrayofclassname_0 xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <classname_0>         <stuff></stuff>     </classname_0>     <classname_0>         <stuff></stuff>     </classname_0> </arrayofclassname_0> 

is there way serialize , able deserialize below from/to list of classname_0?

<?xml version="1.0" encoding="utf-8"?> <arrayofclassname xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <classname>         <stuff></stuff>     </classname>     <classname>         <stuff></stuff>     </classname> </arrayofclassname> 

thanks!

in example classname isn't real root. real root list. have mark list root element. class xmlelement.


Comments