MemoryStream msXml = new MemoryStream(); XmlTextWriter xmlWriter = new XmlTextWriter(msXml, Encoding.UTF8); xmlWriter.WriteStartElement("rss"); xmlWriter.WriteAttributeString("version", "2.0"); xmlWriter.WriteStartElement("channel"); xmlWriter.WriteElementString("title", "Test"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.Flush(); // 确保书写器更新到Stream中 msXml.Position = 0; // 重置流的位置,以便我们可以从头读取 XmlReader xmlReader = XmlReader.Create(msXml);