Encoding problems with XDocument XElement when using ReplaceWith method
问题 I have the following code: XDocument doc = XDocument.Load(file); var x = doc.Descendants("span"); XElement xelm = x.FirstOrDefault(xm => xm.Attribute("class").Value=="screenitems"); Regex rgx = new Regex("^<span class=\"screenitems\">(.*)</span>$"); Match mtc = rgx.Match(xelm.Value); if (mtc.Success) { xelm.ReplaceWith(mtc.Groups[1].Value); } doc.Save(file); When I get a match and replace the content of the XML file loaded into variable doc using the ReplaceWith method for the XElement