XML support
CodeSmith Generator can read template metadata from XML files. To use XML metadata in a template, declare an XmlProperty:
<%@ XmlProperty Name="PurchaseOrder" Schema="PO.xsd" Optional="False" Category="Data" Description="Purchase Order to generate packing list for." %>
When the user runs the template, they choose an XML file for the property. If you supply an XSD schema, Generator builds a strongly typed object model from it, so your template code can use the XML's elements and attributes as properties, with IntelliSense. Without a schema, the property is an XmlDocument.
See XML property examples for complete templates with and without a schema, or watch the XML Property video.
XmlProperty attributes
Name is required; all other attributes are optional.
| Attribute | Description | Required |
|---|---|---|
Name |
The property name shown in the property grid. It's also the name of the variable that holds the value in template code, so it must be a legal identifier in the template's language. With a schema, the variable is a strongly typed object model that Generator builds from the schema; without one, it's an XmlDocument. |
Yes |
Schema |
The XSD schema used to parse the XML file the user chooses. A schema also lets Generator offer IntelliSense for the property in your template. Without a schema, the user can choose any XML document, and the property is an XmlDocument. |
No |
Default |
The default value. If you omit it, the property has no default value. | No |
Category |
The property grid category the property appears in. | No, defaults to Misc |
Description |
Text shown at the bottom of the property grid when the property is selected. | No |
Optional |
Whether the user can leave the property empty. When False, Generator doesn't generate until the user chooses a file; when True, a value isn't required. |
No |
OnChanged |
The event handler to call when the property's value changes. | No |
RootElement |
The relative or full path to the root XML element. | No |
Important
XmlProperty doesn't support every variation and feature of XSD schemas.