Jaa


Microsoft Word, XML, and the hierarchical DataSet

I was finalizing some demos for an internal event here at Microsoft. We have an internal conference for people from the field and elsewhere to learn more about our technologies, do some hands-on labs and so forth. It's goodness.

I am doing a presentation on...yeah- Word, Excel, and the XML story. It's fertile ground, and I never tire of farming it.

One of things I will show is how to build Word documents from XML directly- nothing earth shattering in and of itself as we have a number of canned demos for this. However, I will show how to use .NET and/or SQL Server's XML support to make all of this happen. For example, in my last demo, I use a custom winform app to connect to a database. I pull an order along with order detail from the db and bring them into a dataset in ADO.NET. Then, I create a relationship between them to make the two tables hierarchically related.

(here's how I relate the tables in the Dataset:

dsData.Relations.Add("OrdersDetail"),

dsData.Tables["Table"].Columns["OrderID"],

dsData.Tables["Table1"].Columns["OrderID"]);

dsData.Relations["OrdersDetail"].Nested=true;

Finally, I dump the result to an XML file.

After this, I transform the XML file into another XML file that is constructed differently. This allows me to run an existing XSL against the final XML file and turn it into a nicely formatted Word doc. Too many steps? Not really. It all happens in about a hundredth of a second. I love the flexibility, the adaptability. It plays well in the kind of real-world solutions I have been part of.

Rock Thought for the day: I am a big fan of Big Head Todd and the Monsters. I was listening to the album Riviera on my way to work. It is just great stuff from a mature band that knows the instruments, the music, the soul, and a meaningful song.

 

Rock On

Comments