Tuesday, 27 August 2013

Reading XML Complex Data Type Into a Dataset

Reading XML Complex Data Type Into a Dataset

I'm attempting to read an XML file with a dataset. Then use the tables
inside the dataset to iterate through the information. What I'm having
trouble doing is reading one of the complex data types which would be a
column inside one of the tables.
Hopefully the sample code is better at painting a picture than I am.
XML
<persons>
<person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<sin>123456</sin>
<phone>5555555555</phone>
<address>
<street1>123 fake st</street1>
<zip>12345</zip>
</address>
</person>
So I'm reading the xml file with:
DataSet.readXML(textReader);
DataTable dt = dataSet.Tables["person"] //will let me iterate through
the person
foreach(dataRow dr in dt.Rows)
{
console.writeline(dr[firstName]);
consele.writeline(dr[lastName]);
console.writeline(dr[address]); //This gives me an integer
}
How can I use a similar method to the above and have dr[address] return me
the full address?

No comments:

Post a Comment