I have an XML document as below:
<?xml version="1.0" encoding="utf-8" ?>
<Providers>
<Provider>
<ProviderType>Email</ProviderType>
<ProviderTitle>MyProviderTitle</ProviderTitle>
<DeliveryRules>
<PersonalDelivery>true</PersonalDelivery>
</DeliveryRules>
<ProviderConfiguration>
<SendTo>
<Address>myEmailAddress</Address>
<Address>myEmailAddress</Address>
</SendTo>
</ProviderConfiguration>
</Provider>
<Provider>
<ProviderType>Email</ProviderType>
<ProviderTitle>MyProviderTitle</ProviderTitle>
<DeliveryRules>
<PersonalDelivery>true</PersonalDelivery>
</DeliveryRules>
<ProviderConfiguration>
<SendTo>
<Address>myEmailAddress</Address>
<Address>myEmailAddress</Address>
</SendTo>
</ProviderConfiguration>
</Provider>
</Providers>
Now when I pull this into a dataset using:
DataSet dsConfiguration = new DataSet();
dsConfiguration.ReadXml("myfile.xml"));
How can I iterate through providers?
When it comes to more hierarchical data, you’re much better off deserializing to a strongly typed object graph.
Here is a very quick implementation that should work for your example document:
Obviously this approach requires more plumbing work but if you can get your hands on an XSD that describes your document’s format then you can automatically generate all your classes using the XSD.exe tool.