I uploaded this new article in the Unedited Section of CodeProject.
Abstract
This article describes how we can use XML as a metadata source for SCG Templates. It also shows step-by-step instructions of how to generate strongly typed objects from XSD and use it in the templates to generate text based output. ASP.NET developers can also use this paper as reference to transform XML using ASP.NET scripts and avoid XSLT.
Introduction
We all agree that XML's primary purpose is to facilitate the sharing of data across different systems. However, the same XML can also be used as a powerful input for template generation tools. CodeSmith fans might be already familiar with XmlProperty and can be already seen in a variety of examples. In this article I am going to illustrate how to use XML as a metadata source for SCG templates. XML provides a text-based means to describe and apply a tree-based structure to information and SCG facilitates writing logic and code in your favorite .NET language (C#, Vb.Net etc). By combining these two technologies, we can generate meaningful input & output for a system which was very complex to achieve earlier. In the code generation world, XML is now highly used as a metadata source to generate business objects, data access layers and even user interfaces. The other practice is to generate different application layers based on database structure, but XML is becoming more popular as it provides more flexibility in integrating logic as a metadata source for templates. For example, in this example I defined the class name and its properties, and also specified to generate a UI with a gridview component and paging support. Notice this would have been a bit messy to define in a database structure.
<?xml version="1.0" encoding="utf-8" ?>
<BusinessObjects xmlns="http://www.smartcodegenerator.com">
<class name="Student">
<properties>
<property name="Id" type="String" maxSize="36" />
<property name="Name" type="String" maxSize="96" />
</properties>
<userinterface generate="true">
<uicomponent>GridView</uicomponent>
<gridview paging ="true" rownum="20">
</gridview>
</userinterface>
</class>
</BusinessObjects>
Lets see how to use XML in SCG template.