{"id":319,"date":"2015-01-20T10:38:10","date_gmt":"2015-01-20T00:38:10","guid":{"rendered":"http:\/\/www.docx4java.org\/blog\/?p=319"},"modified":"2015-01-20T11:35:06","modified_gmt":"2015-01-20T01:35:06","slug":"i-have-my-xml-now-what","status":"publish","type":"post","link":"https:\/\/www.docx4java.org\/blog\/2015\/01\/i-have-my-xml-now-what\/","title":{"rendered":"I have my XML, now what?"},"content":{"rendered":"<p>A barrier to using \u00a0content control data binding has been getting a feel for what the solution might look like. \u00a0You have your XML data, but what do you do next?<\/p>\n<p>The audience for this post is broader than docx4j users; its for anyone wanting to easily set up a template docx using XML data binding, just to get a feel for what it is like from an authoring\/Word perspective.<\/p>\n<p>How do you add content controls to your Word document, and map them to the XML data?<\/p>\n<p>For docx4j purposes, you use an OpenDoPE Word AddIn (of which there are two you can try).<\/p>\n<p>Alternatively, Word 2013 introduced the XML mapping task pane (and some additional file format features) . \u00a0The docx linked in my previous blog post highlighted some usability issues with the XML mapping pane.<\/p>\n<p>This post presents a &#8220;fast start&#8221; way you can try. \u00a0Simply <a href=\"http:\/\/webapp.docx4java.org\/OnlineDemo\/xml_to_w15_bindings.html\">upload your XML file here<\/a>, and it will give you back a docx, with content controls mapped to that sample XML.<\/p>\n<p>To take the following XML for an invoice as an example:<\/p>\n<p><a href=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/invoice-xml.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-323\" title=\"invoice-xml\" src=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/invoice-xml.png\" alt=\"\" width=\"849\" height=\"791\" srcset=\"https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/invoice-xml.png 849w, https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/invoice-xml-300x279.png 300w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/a><\/p>\n<p>You&#8217;d get back the following <strong>Word 2013<\/strong> docx (note that <strong>Word 2010<\/strong> silently strips the repeats without warning):<\/p>\n<p><a href=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-322\" title=\"result\" src=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/result-165x300.png\" alt=\"\" width=\"165\" height=\"300\" srcset=\"https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/result-165x300.png 165w, https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/result.png 454w\" sizes=\"auto, (max-width: 165px) 100vw, 165px\" \/><\/a><\/p>\n<p>In &#8220;design mode&#8221;, it looks like:<\/p>\n<p><a href=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/designmode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-324\" title=\"designmode\" src=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/designmode.png\" alt=\"\" width=\"502\" height=\"288\" srcset=\"https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/designmode.png 502w, https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/designmode-300x172.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/a><\/p>\n<p>Whether you&#8217;re in design mode or not, you can edit the content of a content control, then to satisfy yourself that things are working correctly, save the docx, then unzip it and see your altered data in \/customxml\/item1.xml<\/p>\n<p>This idea is that once you have the basic docx, you can quickly\/easily edit it in Word to make it prettier:<\/p>\n<p><a href=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/formatted.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-325\" title=\"formatted\" src=\"http:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/formatted-300x274.png\" alt=\"\" width=\"300\" height=\"274\" srcset=\"https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/formatted-300x274.png 300w, https:\/\/www.docx4java.org\/blog\/wp-content\/uploads\/2015\/01\/formatted.png 831w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The tool recognises and uses the following content control types:<\/p>\n<ul>\n<li><strong>repeats<\/strong>: automatically detect repeats and set up suitable content control structures (we use a table if there&#8217;d be more than one column) fully populated with the XML data\n<ul>\n<li>note that these are <strong>Word 2013 repeatingItem<\/strong> structures, not OpenDoPE repeats. \u00a0(We recommend you use OpenDoPE repeats, but the tool creates Word 2013 repeatingItems, so you can see what Word 2013 users get out of the box).<\/li>\n<\/ul>\n<\/li>\n<li><strong>pictures\/images<\/strong>: will use a picture content control if the field contains base64 encoded data, or the string PICTURE or string IMAGE<\/li>\n<li><strong>checkbox<\/strong>: generated if value is true or false<\/li>\n<li><strong>escaped Flat OPC XML<\/strong>: a bound rich text content control will be inserted if the element contains the string FLAT-OPC or the string \u00a0 ?mso-application progid=&#8221;Word.Document<\/li>\n<li><strong>date control<\/strong>: used if the element content is the string DATE<\/li>\n<\/ul>\n<p>Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A barrier to using \u00a0content control data binding has been getting a feel for what the solution might look like. \u00a0You have your XML data, but what do you do next? The audience for this post is broader than docx4j users; its for anyone wanting to easily set up a template docx using XML data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":3,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":321,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/319\/revisions\/321"}],"wp:attachment":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}