Experts !
i am very new to XML. However, a webapp collects data in XML form and i have to display it (and enable edit) in an ASP.Net GridView. i need your help, please.
<?xml version="1.0"?>
<Answers>
<AnswerSet>
<Answer questionId="MRN">4444</Answer>
<Answer questionId="FName">test</Answer>
<Answer questionId="LName">patient</Answer>
<Answer questionId="AddressPt">blah blah</Answer>
<Answer questionId="Governorate">xxxx</Answer>
<Answer questionId="InitialCSF">Negative</Answer>
<Answer questionId="Diagnosis"></Answer>
<Answer questionId="Description">
</Answer>
</AnswerSet>
<AnswerSet>
<Answer questionId="MRN">1</Answer>
<Answer questionId="FName">1</Answer>
<Answer questionId="LName">1</Answer>
<Answer questionId="AddressPt">1</Answer>
<Answer questionId="InitialCSF">Positive</Answer>
<Answer questionId="Diagnosis">dx</Answer>
<Answer questionId="Description">
</Answer>
</AnswerSet>
</Answers>
Easiest way I can think of to bind the XML to a gridview is to to load the xml to a DataSet and then bind the DataSet to the gridview:
Reason for doing
ds.Tables[0]is that your example contains 2 sets ofAnswersand when you load the DataSet with your XML, the first DataTable will contain as many rows as sets of answers you have on your XML while the second table will contain all the rows from all the set of answers.The way LinqPad displays it is as follows:
UPDATE: