XML:
="1.0"="ISO-8859-1"
<IMPORT ExportDate="2016-03-02" Exercise="1" User="asa" Version="8.73" BusinessUnit="abc(1236)">
<BusinessUnitAdmin>
...
...
</BusinessUnitAdmin>
<BusinessUnit>
..
..
</BusinessUnit>
<Exercise>
..
..
</Exercise>
<Exercise>
..
..
</Exercise>
<Contact>
..
</Contact>
</IMPORT>
I am trying to export this xml to excel, while also maintaining the schema of xml.
For this, i have tried converting the xml to Dataset and then exporting it to excel.
It works correctly if i remove the root element - IMPORT from the XML. However since it has '**BusinessUnit** as attribute, its preventing to read "BusinessUnit" as element.
For this, i am trying to read XML from second element `- <businessunitadmin>` ; but unable to do.
C# Code :
DataSet ds = new DataSet();
string path = "C:\\abc\\xyz.xml";
ds.ReadXml(path);
ExportDataSetToExcel(ds);
Error : "A column named 'BusinessUnit' already belongs to this DataTable: cannot set a nested table name to the same name."
What I have tried:
I have tried using LINQ :
XDocument xdoc = XDocument.Load(path);
XElement import = xdoc.Element("IMPORT");
XElement contact = import.Element("Contact");
StringReader theReader = new StringReader(contact.ToString());
ds.ReadXml(theReader);
It works correctly,but this way, i have to manually read all elements.
I also tried reading elements using - `var allElements = xdoc.Descendants()`;
but unable to store specfic elements in dataset.
Please help.