CodeSmith and XML
Stefan Cullmann points out CodeSmith's current lack of good XML support. I agree completely and dramatically improving XML support in CodeSmith is very high on my priority list so I decided to take this opportunity to let you all know what I am planning to do and see what you think.
Currently, CodeSmith only supports XML serializable objects. Basically, you create an object that is XML serializable, create a property of this type in your template, CodeSmith then allows you to select an XML file which will be deserialized into an instance of your object, and you can then proceed to use the information provided in this object in a fully object oriented and strongly typed fashion. Even though you can easily use XSD.exe to generate this object for you based on either an XSD or infered from an XML instance document, it is still a bit of a pain to setup and needs to be updated as you decide to add more information to your XML document.
I am planning to add 2 additional ways of supporting XML in CodeSmith. First, I plan to put together a simple designer that will allow you to select any XML file and CodeSmith will load this XML for you into an XmlDocument object and you will be able to traverse the information using the XML DOM.
Secondly, I plan to implement my own version of XSD.exe that will be embedded into the CodeSmith engine and will take any XSD and dynamically create a strongly typed object model for it on the fly. This will basically give you the best of both worlds. You will be able to use XML as an input source and you will also be able to write your templates against a strongly typed object model. Here is a little sample of what this might look like:
<%@ XmlProperty Name="MyOrder" Schema="MyOrderSchema.xsd" %> <% foreach (DetailLine detailLine in MyOrder.DetailLines) { %> ProductID: <%= detailLine.ProductID %> Quantity: <%= detailLine.Quantity %> <% } %>
I'm interested to know what you guys think of this so feel free to comment on this post and let me know.