我有一个定义如下的类:
[XmlRoot("ClassName")]
public class ClassName_0
{
//stuff...
}
然后我创建一个 ClassName_0 列表,如下所示:
var myListInstance= new List<ClassName_0>();
这是我用来序列化的代码:
var ser = new XmlSerializer(typeof(List<ClassName_0>));
ser.Serialize(aWriterStream, myListInstance);
这是我用来反序列化的代码:
var ser = new XmlSerializer(typeof(List<ClassName_0>));
var wrapper = ser.Deserialize(new StringReader(xml));
如果我将其序列化为 xml,则生成的 xml 如下所示:
<?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>
有没有办法序列化并能够从/到 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>
谢谢!