If you're using Visual Studio 2012 (or greater) and you're targeting .NET 4.5 (or greater) then Visual Studio can create a class for you that matches the XML:
- Copy the XML to your clipboard
- From within Visual Studio: Edit --> Paste Special --> Paste XML As Classes
Then you'll need to serialize the data from XML to your newly created class to create a new object:
var myObject = LoadFromXmlString<DATA_PROVIDERS>(xmlData);
public static T LoadFromXmlString<T>(string xml)
{
T retval = default(T);
try
{
XmlSerializer s = new XmlSerializer(typeof(T));
MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(xml));
retval = (T)s.Deserialize(ms);
ms.Close();
}
catch (Exception ex)
{
ex.Data.Add("Xml String", xml);
throw new Exception("Error loading from XML string. See data.", ex);
}
return retval;
}