I am trying to write a app.config / web.config error correcting app which will audit our developers applications for incorrect environment settings. I am using Linq to XML to accomplish this and I am hitting a snag.
var query =
from el in doc.Descendants().Element("SMTPHost")
select el;
foreach (XElement host in query)
{
if (Regex.IsMatch(el.Value, "mail.mycompany.com")
{
el.Value = Regex.Replace(el.Value,
"mail.mycompany.com", "devmail.mycompany.com");
}
}
When I run this, it concatenates all the child text values for one of the ancestor nodes of the correct element and removes all of the child elements.
Is there a better way to do this sort of thing?
Thanks!