I have a table in SQL Server that has a XML type column.
That column has dynamic value in XML type, I want read it table in C#.
How can we separate each property in my XML?
I have a table in SQL Server that has a XML type column.
That column has dynamic value in XML type, I want read it table in C#.
How can we separate each property in my XML?
Get the column from database like this. CodeAndPassword(string) is class's property.
CodeAndPassword = Serializer.DeSerialize<Config>(row.Field<string>("Explanation"));
And your DeSerialize function sholud be like this
public static string DeSerialize<T>(string xml)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = false;
xmlDoc.LoadXml(xml);
Config config = Serializer.DeSerialize<Config>(xmlDoc.DocumentElement);
string code = config.Login.Code;
string password = config.Login.Pass;
return code + "+" + password;
}
And here is our Config Class
[Serializable]
public class Config
{
public ConfigLogin Login { get; set; }
}
[XmlRoot("Login")]
public class ConfigLogin
{
public string Code { get; set; }
public string Pass { get; set; }
}