Wednesday, 18 February 2015

Using C# Dataset to read xml file



I have an xml file with the below data:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Tables xmlns:xsi="http://ift.tt/ra1lAU">
<countries>
<country country_id = "1" name = "Afghanistan"/>
<country country_id = "2" name = "Albania"/>
<country country_id = "3" name = "Algeria"/>
</countries>
</Tables>


When I try to use the below C# code,



DataSet ds_XMLData= new DataSet();
ds_XMLData.ReadXml(XMLFile);


I get two tables: countries with one column countris_id and one row with value "0" country with 3 columns - additional column being countries_id and all rows with value "0"


Can you please help me understand why is a single table countries not present in the dataset with only two columns - country_id and name?


Also, why is the additional column - countries_id added in all the tables.


Note:- I would like to keep on using the attribute based xml file format.


No comments:

Post a Comment