public string XmlSerialize<T>(T obj)
??????? {
??????????? System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(T));
??????????? MemoryStream stream = new MemoryStream();
??????????? System.Xml.XmlWriterSettings setting = new System.Xml.XmlWriterSettings();
??????????? setting.Encoding = new UTF8Encoding(false);
??????????? setting.Indent = true;//开启缩进
??????????? using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stream, setting))
??????????? {
??????????????? XmlSerializerNamespaces _namespaces = new XmlSerializerNamespaces(
??????????????? new XmlQualifiedName[] {
??????????????? new XmlQualifiedName(string.Empty, string.Empty)
??????????????? });
??????????????? //writer.WriteStartDocument(true);
??????????????? xs.Serialize(writer, obj, _namespaces);
??????????? }
??????????? return Encoding.UTF8.GetString(stream.ToArray());
??????? }
调用: