@fzkim , Welcome to Microsoft Q&A, you could try the following code to change part of a string in the xml file.
Code:
XDocument doc=XDocument.Load(path);
var result = doc.Descendants("value").Descendants().Cast<XElement>().ToList();
string elestr=string.Empty;
for (int i = 0; i < result.Count(); i++)
{
StringWriter myWriter = new StringWriter();
elestr = result[i].ToString();
HttpUtility.HtmlEncode(elestr,myWriter);
result[i].ReplaceWith(Environment.NewLine+myWriter.ToString()+Environment.NewLine);
}
doc.Save(path);
string txt=File.ReadAllText(path);
txt = txt.Replace("&", "&");
txt = txt.Replace(""", "\"");
File.WriteAllText(path, txt);
var lines = File.ReadAllLines(path).Where(line => !String.IsNullOrWhiteSpace(line));
File.WriteAllLines(path, lines);
Note: Please add namespace in your app:
using System.IO;
using System.Linq;
using System.Web;
using System.Xml.Linq;
Tested result:
Hope this could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.