Jan 20 2015
I have my XML, now what?
A barrier to using content control data binding has been getting a feel for what the solution might look like. You 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 binding, just to get a feel for what it is like from an authoring/Word perspective.
How do you add content controls to your Word document, and map them to the XML data?
For docx4j purposes, you use an OpenDoPE Word AddIn (of which there are two you can try).
Alternatively, Word 2013 introduced the XML mapping task pane (and some additional file format features) . The docx linked in my previous blog post highlighted some usability issues with the XML mapping pane.
This post presents a “fast start” way you can try. Simply upload your XML file here, and it will give you back a docx, with content controls mapped to that sample XML.
To take the following XML for an invoice as an example:
You’d get back the following Word 2013 docx (note that Word 2010 silently strips the repeats without warning):
In “design mode”, it looks like:
Whether you’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
This idea is that once you have the basic docx, you can quickly/easily edit it in Word to make it prettier:
The tool recognises and uses the following content control types:
- repeats: automatically detect repeats and set up suitable content control structures (we use a table if there’d be more than one column) fully populated with the XML data
- note that these are Word 2013 repeatingItem structures, not OpenDoPE repeats. (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).
- pictures/images: will use a picture content control if the field contains base64 encoded data, or the string PICTURE or string IMAGE
- checkbox: generated if value is true or false
- escaped Flat OPC XML: a bound rich text content control will be inserted if the element contains the string FLAT-OPC or the string ?mso-application progid=”Word.Document
- date control: used if the element content is the string DATE
Have fun.
Deepak said,
December 22, 2015 @ 6:16 pm
I need to use this in my webapp. Can I get the source code of this web app where I can convert xml to word bindings?