I used a method from @yadavr (many thanks for that great solution) and question he answered for issue LINK.
This works great when you want to convert List and show it to a DataGridView. Method is:
public static class XElementExtensions
{
public static DataTable ToDataTable(this XElement element)
{
DataSet ds = new DataSet();
string rawXml = element.ToString();
ds.ReadXml(new StringReader(rawXml));
return ds.Tables[0];
}
public static DataTable ToDataTable(this IEnumerable<XElement> elements)
{
return ToDataTable(new XElement("Root", elements));
}
}
After this, I only added DataSet as source of DataGridView.
However, I have found one problem when in XElement there are two nodes with same name, but different namespaces. First of all, if all nodes have unique name (regardless of a namespace), all columns in DataGridView have names like name of nodes, but without namespace. So, instead of something like "cim:Location", it will just show "Location". Problem emerges once there are "cim:Location" and "dns:Location". In that case I get exception saying that I have ambiguous column names.
Is there any way to include namespaces in the column names ?
I tried to use different approaches, but nothing is working for me.