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 variable xelm, the content of the XML file is getting encoded, so instead of having a tag like <p> I get <p>.
So How can I prevent that it encodes into html but actually replaces with the matched regex expression?
I have looked at some of the solutions here, like using XElement.Parse method or HTTPUtility.HtmlDecode, but I couldn't get it to work. It still encodes like html.
No comments:
Post a Comment