C# DataSets and the Magic of ReadXML
I've worked on several applications where we used .NET DataSets as the container for passing records between web services and other components. They work pretty well to keep things nice and loosely coupled when you're building lots of separate components that may or may not all be using the same language, etc.
One of the greatest things that they included in the DataSet classes is the ability to read and write them to XML files. That gives you not only an interchange format, but a file-based version of it pretty quickly. You can easily use those files as your "gold standard" for building all of the components at once. As long as each component emits and consumes that sample file, things are golden.
Anyway, one of the side benefits of that ability to read/write those XML files is that it not only handles the DataSets you create via code. The ReadXml() method actually will convert nearly any XML file into a DataSet. That can come in really handy when your entire application is already passing DataSets around.
That's because nearly any application of reasonable size pulls in information from somewhere outside of the control of your code. In many of those cases, that data will be in XML format. You can, therefore, use the ReadXml() to get DataTable access to all kinds of useful XML stuff.
When it gets read in, .NET does some pretty cool automatic stuff, like creating identifier columns on your tables, etc. However, if, unlike the "normal" DataSets, your imported XML data is nested 2-3 or more levels deep, it can be kind of hard to predict exactly what the DataTable structure will look like.
I'm not a huge fan of automatic or "magic" methods, because you usually have absolutely no way to see inside the black box. That's not the case here because, while the method does some pretty cool magic, it is still possible to see inside of what it does.
I decided that I needed something to deal with the black box today and after dinner tonight, I wrote a quick console app to take an arbitrary XML file and dump out all of the tables, columns and rows in the DataSet in a way that makes it more clear how you'll need to use the tables to grab the data you're after.
That's the information you're going to need to establish your DataRelation objects to tie things together. It's been fairly illuminating for the few files I've sent through it so far and I'm thinking this will be a permanent part of my utilty folder.
I run it using Powershell and the "Out-File" pipe the output to a file, giving me a record of that schema (which I find much easier to read than the output of the WriteXmlSchema() method).
In case you'd like to use it as well, here's a copy of the code.

