ihrb
ihrb

Reputation: 11

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?

Upvotes: 1

Views: 826

Answers (1)

Luke Willis
Luke Willis

Reputation: 8580

You can use dr.GetChildRows("address")

var address = dr.GetChildRows("address");
Console.WriteLine(address["street1"]);
Console.WriteLine(address["zip"]);

Upvotes: 1

Related Questions