我正在序列化一个像下面这样的类
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
StringWriter sw = new StringWriter();
XmlSerializer serializer1 = new XmlSerializer(typeof(List<student>), new XmlRootAttribute("Response"));
XmlTextWriter xmlWriter = new XmlTextWriter(sw);
serializer1.Serialize(xmlWriter, ls, namespaces);
sw.ToString()
下面的结果字符串
<?xml version="1.0" encoding="utf-16"?>
<Response><student><name>xxx</name></student></Response>
但是,如何向根元素(响应)添加属性?像下面一个
<?xml version="1.0" encoding="utf-16"?>
<Response status="1"><student><name>xxx</name></student></Response>