{"id":303,"date":"2011-03-15T02:24:04","date_gmt":"2011-03-15T02:24:04","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?p=303"},"modified":"2011-03-15T17:46:53","modified_gmt":"2011-03-15T17:46:53","slug":"changing-the-schema-for-this-open-xml-document-generation-system","status":"publish","type":"post","link":"https:\/\/www.ericwhite.com\/blog\/2011\/03\/15\/changing-the-schema-for-this-open-xml-document-generation-system\/","title":{"rendered":"Changing the Schema for this Open XML Document Generation System"},"content":{"rendered":"<p>Flexibility in a document generation system is very important to its usability.\u00a0 We all know how it works.\u00a0 You\u2019ve been commissioned by the marketing department to put together a mailing to 50,000 customers.\u00a0 After doing the work of putting together the template document, the marketing department *will* come ask for changes to the data and to the template document.\u00a0 In the following screen cast, I show the process of adjusting the XML data that drives the document generation system, as well as adjusting the template document to use that data.<\/p>\n<p>This post is the 12th in a series of blog posts on generating Open XML documents. Here is the complete list: <a href=\"https:\/\/www.ericwhite.com\/blog\/map\/generating-open-xml-wordprocessingml-documents-blog-post-series\/\">Generating Open XML WordprocessingML Documents Blog Post Series<\/a><\/p>\n<div id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:f87654c9-94c2-434a-89bb-4f58887c8665\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; display: inline; float: none; padding: 0px;\">\n<div><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"448\" height=\"252\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/xwf3jTtEncU?hl=en&amp;hd=1\" \/><embed type=\"application\/x-shockwave-flash\" width=\"448\" height=\"252\" src=\"http:\/\/www.youtube.com\/v\/xwf3jTtEncU?hl=en&amp;hd=1\"><\/embed><\/object><\/div>\n<div style=\"width: 448px; clear: both; font-size: .8em;\">Shows changing the schema and the template document.<\/div>\n<\/div>\n<p>There are lots of disadvantages to this approach of editing C# code in content controls in a Word document:<\/p>\n<ul>\n<li>It requires a developer to put together the template document.<\/li>\n<li>If you write C# code that doesn\u2019t compile in a content control, you don\u2019t see any errors until you try to compile the generated program.<\/li>\n<li>There is no Intellisense when editing this code.\u00a0 In a couple of places, I ended up first getting a snippet of code to work in Visual Studio, and then pasting that code into the content control.\u00a0 This is far from ideal.<\/li>\n<li>The code that generates C# code from the template document is not long \u2013 only about 390 lines of code (see ProcessTemplate.cs in the Zip file).\u00a0 However, it is a bit gnarly, particularly the bits that make it so that you can have Value, Table, or Conditional content controls within a Conditional content control.\u00a0 However, the C# code that you write inside the template document is not so complex \u2013 just the code to generate the code.<\/li>\n<\/ul>\n<p>There are advantages too:<\/p>\n<ul>\n<li>The code is directly associated and stored with the document.\u00a0 This is called \u2018lexical proximity\u2019 \u2013 you don\u2019t need to find code in another file somewhere, and you don\u2019t need to keep code and the template document in sync.<\/li>\n<li>You can pull data from *any* data source.\u00a0 I could easily modify the template document to use OData or the Managed Client Object Model to pull data from a SharePoint list.\u00a0 I could also write some ADO.NET code to pull data from any SQL database.<\/li>\n<\/ul>\n<p>It is not clear that the advantages outweigh the disadvantages.\u00a0 In the next post in this series, I\u2019m going to limit the data source to XML, and use XPath in the content controls.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flexibility in a document generation system is very important to its usability.\u00a0 We all know how it works.\u00a0 You\u2019ve been commissioned by the marketing department to put together a mailing to 50,000 customers.\u00a0 After doing the work of putting together the template document, the marketing department *will* come ask for changes to the data and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"categories":[7,3,5],"tags":[],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-document-generation-series","category-open-xml","category-wordprocessingml"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=303"}],"version-history":[{"count":3,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/303\/revisions\/317"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/tags?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}