XmlWriter encoding issues
问题 I have the following code: MemoryStream ms = new MemoryStream(); XmlWriter w = XmlWriter.Create(ms); w.WriteStartDocument(true); w.WriteStartElement("data"); w.WriteElementString("child", "myvalue"); w.WriteEndElement();//data w.Close(); ms.Close(); string test = UTF8Encoding.UTF8.GetString(ms.ToArray()); The XML is generated correctly; however, my problem is the first character of the string 'test' is ï (char #239), making it invalid to some xml parsers: where is this coming from? What