Parse XML Physical Path to Class
Get XML from Physical Path and Parse into Class
Source
public static T DeserilizeXML<T>(this string physicalPath) where T : class
{
try
{
if (!string.IsNullOrEmpty(physicalPath) && !string.IsNullOrWhiteSpace(physicalPath))
{
if (File.Exists(physicalPath))
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<T>));
using (TextReader textReader = new StreamReader(physicalPath))
{
return (T)xmlSerializer.Deserialize(textReader);
}
}
catch (Exception)
{
return File.ReadAllText(physicalPath).ParseToClass<T>();
}
}
}
}
catch (Exception)
{
}
return null;
}
Example
none