I want to modify some xml files from a given location and I have two methods to do so
Method1
-->using XDocument to parse and modify the file
Method2
-->using Regex to parse and modify the file
But some files that I want to modify are not a valid xml, so how do I efficiently check for each of the files whether they are modifiable using XDocument
or not and perform the operations accordingly like
string[] filesindirectory = Directory.GetFiles(location, "*.xml",SearchOption.AllDirectories);
foreach (string file in filesindirectory)
{
if(//file is readable/modifiable using XDocument)
{
//perform Method1
}
else
{
//perform Method2
}
}