I have a XML file which I want to convert into an array. I have tried using Xmlserialzer class and it's working but for some reasons I am not allowed to use it in my project. I have looked at few solutions but none of them match the requirement I have. Please guide me regarding this. Below is the sample XML file.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PatientRecord>
<Patient>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<Age>46</Age>
</Patient>
<Patient>
<FirstName>Martha</FirstName>
<LastName>Stewart</LastName>
<Age>51</Age>
</Patient>
</PatientRecord>
array must be like:
{"Firstname", "LastName", "Age"}
{"John","Smith","46"}
{"Martha", "Stewart", "51"}
What I have tried:
XmlReader xmlFile;
xmlFile = XmlReader.Create(inputPath, new XmlReaderSettings());
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(xmlFile);
int row_count = ds.Tables[0].Rows.Count;
int col_count = ds.Tables[0].Columns.Count;
string[,] data = new string[row_count, col_count];
for(int i = 0; i < row_count; i++)
{
for(int j = 0; j < row_count+1; j++)
{
data[i, j] = ds.Tables[0].Rows[i][j].ToString();
data[i, j] = ds.Tables[0].Rows[i][j].ToString();
data[i, j] = ds.Tables[0].Rows[i][j].ToString();
}
}
I have tried creating a 2-d array which is getting values but not tags.
Configuration.