Extracting Metadata - Introducing the Process
(Page 2 of 22 )
The code generation process needs a single monolithic XML metadata input. But a monolithic metadata file is hard to manage. Different people may perform different metadata extraction and code outputting tasks. Chapter 3 shows how to make code generation a granular process. It makes no sense to create a granular process and then have it rely on a monolithic file that everyone is trying to modify. So, I’ll show you how to merge individual XML metadata into a transient monolithic file in the “Merging Metadata” section of this chapter.
Figure 2-2 is a high-level view of metadata. On the right, the single monolithic XML metadata file is composed of four segments. You might add another segment or two, such as report definitions, but you’ll have a small number of high-level sections in the XML metadata document.
The monolithic XML metadata file is created on individual developers’ machines and is transient. You’ll output it to disk for debugging, but you don’t want to put it under source control. One of the differences between hacking around with code generation and making it a conscious process is intelligently incorporating source control. By keeping only the individual metadata files under source control, you gain important flexibility for your team.
Seeing all these discrete steps might be making you nervous, particularly if you’ve worked with the tedious process of generating strongly typed DataSets in Visual Studio. I’m committed to one-click code generation smoothly integrating these granular processes. You’ll see details of one-click activation of the multistep code generation process in Chapter 3, so you’ll need to trust me on this and postpone testing these tools until then when you’ll have the metadata, the templates, and the generation tool.
Understanding Metadata Sources Metadata is all of the changeable information you need to build source code. This is the bulk of what changes between your applications. Because the easiest metadata to visualize is from databases, I’ll often talk about metadata in relation to data structures—database fields and columns. Clearly, not all metadata is related to data structures.

Figure 2-2. Metadata sources
If metadata is literally any data you need to build your application, you can get it from anywhere. It makes no difference to later processing where you get the metadata. There are at least seven kinds of metadata sources as follows:
- Schema definitions such as XSD
- Databases such as SQL Server
- Manually entered freeform metadata
- Web Services via Web Service Description Languages (WSDLs)
- External sources, such as mainframes, Excel, and so on
- Design tools such as Unified Modeling Language (UML)
- Existing applications and source code
You can further divide these types into categories based on how you extract the metadata. You extract using .NET if the source has a programmatic interface such as databases, external sources, and existing applications. You retrieve it using XSLT if it’s an XML source such as XSD, WSDL, and XMI output from UML diagrams (see Footnote 1). You can also manually enter metadata by typing in the XML. As you can see in Figure 2-2, regardless of the process, you create a series of individual files.
(Footnote 1. I win Bingo with five acronyms in one sentence! XML is self-describing data whose structure can be defined using an XSD schema. Appendix A discusses XML and XSD. WSDL is basically a specific subset of XML used to describe Web Services. UML is the Unified Modeling Language and is a diagramming standard intended to improve communication during software design processes. XMI is another subset of XML that’s designed for exchanging UML information.)
You can also categorize metadata sources by the high-level element that contains them in the monolithic metadata file. There are only a few broad cate-gories—such as data structures describing data, class structures describing data and functionality, and User Interface (UI) structures describing UI details.
Because there are so many metadata sources, I could write a very long chapter on metadata extraction, but it would be tedious and repetitive. So, I’ll tell you a little about each of these sources and then follow up with a deeper discussion of three metadata sources: XSD schemas, SQL-92 databases (including SQL Server), and freeform metadata. These three sources represent the three key approaches to metadata extraction: XSLT templates, .NET programs, and manual entry. You’ll have to develop your own extraction tool for the other five metadata source types (and any others I omittted), but this chapter will give you a significant head start on writing them.
This is from Code Generation in Microsoft .NET, by Kathleen Dollard (Apress, ISBN 1590591372). Check it out at your favorite bookstore today. Buy this book now. |
Next: Using Schema Definitions Such As XSD >>
More Database Articles
More By Apress Publishing