What You Get
This article shows you how to build and use an XML generator (XMLCreator.exe) and a pair of XML viewers: a straight-VB version for the desktop (VBXMLTree.exe) and a thin-client version you execute with DHTML (XMLViewer.exe). The source also includes a Cascading Style Sheet (CSS) designer (CSS.vbp) that lets you format XML pages visually. This set of applications enables you to generate an XML document from your database schema, then view and interrogate that data.

The XML generator lets you take your existing database, create a visual query against it, and generate an XML document. This means you can use any of your database schema elements, automating the process to generate new XML documents when information changes. It also means you don't have to go through the effort of creating your XML documents manually; instead, this app lets VB do the dirty work for you.

The XML viewer lets you view any XML document, whether you generated it with the XML generator or someone else created it. You can launch the viewer from the main XML generator form. We tested the viewer by surfing the Internet and collecting as many XML documents as we could find. We also tested it with ADO-generated XML recordsets. The viewer performs ably in all cases we could find. After you create your XML pages, you can give them a nice appearance by laying them out in the CSS designer.

Creating this set of apps requires you to combine several disparate technologies, including SQL-DMO, ADO, treeview programming and parsing, and DHTML. Many of the technologies have important uses that go beyond the issue of XML, so carefully perusing the source and ideas of this article can prove instructive, even if you have no immediate plans to use XML. Specific technologies you'll learn about in this article include:

1. SQL Server Programming With DMO
You need to use SQL-DMO to build an application that communicates with SQL Server objects. This article uses SQL-DMO to connect to SQL Server, interrogate the server for a list of databases, and drill down from databases to tables to fields. You can take the SQL-DMO code in the generator and viewer apps and put it to use in non-XML apps quite easily.

2. ADO Stored Procedure Programming
This article serves as a primer for calling SQL stored procedures using ADO. Perhaps the most valuable technique it demonstrates is how to call sp_fkeys, a complex SQL Server-provided stored procedure that enables you build the treeview hierarchy. You use this technique to interrogate the table relationships, determine the primary key/foreign key relationships, and use this information to represent the hierarchies of the table visually. You can get a lot of mileage with this technique by using it in a visual query builder. The ADO code also gives you a glimpse of ADO 2.1's ability to save recordsets as XML.

3. Treeview Programming
You will also learn how to populate a treeview control with related information. The technique itself is trivial, but you won't find it in VB's documentation, especially when the example link for the control is disabled.

4. Treeview Parsing
You can employ some of the techniques you learn in building an XML document to build other types of documents by parsing the treeview control once you put it together. Parsing the treeview control consists of drilling down on each level of the tree, then moving back to the top. You can find several valuable and reusable code snippets to help you accomplish a variety of your special parsing needs.

5. Building a DHTML Project
Experienced developers who have yet to explore DHTML in detail can use this project as a starting point for comparing how you build projects in straight VB versus DHTML. You use VB to create a local client for the desktop, and a VB DHTML project to create a thin client that can run over the Internet inside a browser. You might find it fun to put both projects side by side, taking note of their similarities and differences. You can also reference the VB project for how-to approaches and compare these to your implementations of identical functionality in DHTML.