Here my xml is setup as follows: This is coming via a webservice.
<doc>
<str name="data_id">XXXXXXX</str>
<str name="data">YYYY</str>
<str name="data2">zzzz</str>
...
..
<doc>
<doc>
<str name="data_id">X1X1X1X1X1X1X1</str>
<str name="data">Y1Y1Y1Y1</str>
<str name="data2">z1z1z1z1</str>
...
..
<doc>
I am converting the whole xml into a datatable.
How do I get the column header as column attributes. The resulting datatable have to be in the format as
data_id data
xxxxx yyyy
After loading xmldocument I have the following code which I have written to convert the whole thing into a csv string.
Stream k = r.GetResponse().GetResponseStream();
string csvOut = string.Empty;
var doc = XDocument.Load(k);
StringBuilder sb = new StringBuilder(100000);
DataTable table1 = new DataTable();
foreach (XElement node in doc.Descendants("doc"))
{
foreach (XElement innerNode in node.Elements())
{
sb.AppendFormat("{0},", innerNode.Value);
}
sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
}
csvOut = sb.ToString();
I am trying to get the headers as data_id , data etc