System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(Hotel)); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8); xs.Serialize(ms, h57); writer.Close(); Response.Write(System.Text.Encoding.UTF8.GetString(ms.GetBuffer())); }
此方法不用写到硬盘,比较方便