XML Support

CodeSmith allows you to store metadata in external XML files. To incorporate XML metadata in your templates, you use an XmlProperty directive:

<%@ XmlProperty PurchaseOrder" Schema="PO.xsd" Optional="False" Category="Data" Description="Purchase Order to generate packing list for." %>
XmlProperty Directive Attributes

The XmlProperty directive has six possible attributes. The Name attribute is required, and the other attributes are optional.

Name

The Name attribute is used as the name of the property when it is displayed on the template's property sheet in CodeSmith Explorer. This is also the variable name that is used to store the value of the property within the template. This must be a legal variable name within the template's language. For example, if the template uses C# as its language, then the name must follow the rules for C# variables. If a schema is specified, the variable will point to a strongly typed object model that CodeSmith generates based on the schema.  If no schema is specified, it will point to an instance of the XmlDocument class.

Schema

The Schema attribute specifies an XSD schema to be used to parse the XML file chosen by the user at runtime.

Specifying a schema file allows CodeSmith to supply IntelliSense help for the XmlProperty instance within your template.

If you do not specify a value for the Schema attribute, then the user can select any XML document at runtime, and the property will return an instance of the XmlDocument class.

Default

The Default attribute is used to set the default value for this property. If you omit this attribute, then CodeSmith does not supply a default value for the property.

Category

The Category attribute specifies what category this property should appear under in the CodeSmith Explorer property sheet. If you omit this attribute, CodeSmith will place the property in a category named Misc.

Description

The Description attribute supplies descriptive text to be displayed at the bottom of the property sheet when this property is selected.

Optional

The Optional attribute specifies whether or not this property is optional. If a user does not specify a parameter that is not optional then CodeSmith will not let them proceed. A value of true means that a value for the property is not required, and a value of false means that a value for the property is required.

XmlProperty does not support all variations and features of XSD schemas. In general, if an XSD schema can be successfully loaded into the Visual Studio .NET schema designer then it should work in CodeSmith.