0

i want to convert XML data into data table.my XML file contains many nested tags.how can i display those data in a data table using C#

<school>
   <staff>
      <staffname>raj</staffname>
      <staffname>rani</staffname>
   </staff>
   <students>
      <firstclass>
        <name>nani</name>
        <rollno>1</rollno>
      </firstclass>
      <secondclass>
        <name>rani</name>
        <rollno>1</rollno>
      </secondclass>
</students>
</school>

this is the sample file .Now i want to display this data in a Data Table using c#.

can any one help me to solve this issue

5
  • Have you tried anything? And possible ideas how you might want to do this? Commented Jul 19, 2016 at 13:19
  • Possible duplicate of Convert Xml to DataTable Commented Jul 19, 2016 at 13:23
  • @amuz i have tried with a single tag and i got the result like <details> <name>akhil<//name> </details> i used the same format Commented Jul 19, 2016 at 13:26
  • @abhi i have nearly 1000 xml tags so,its difficult to write for all the tags Commented Jul 19, 2016 at 13:29
  • @naveenkumar chk my solution below it will help you out, keep the xml in txt file and give filename in filepath Commented Jul 19, 2016 at 13:31

1 Answer 1

2

You can use the following code

 DataSet dsTest = new DataSet();
 dsTest.ReadXml(filepath, XmlReadMode.Auto);
 DataTable dt = dsTest.Tables[0];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.