Page 1 of 1

CustomXMLBinding Example

PostPosted: Thu Mar 29, 2012 10:56 pm
by Raj
I tried CustomXmlBinding from the sample code provided and was able to generate the output. However when I tried using a different input file it failed due to the line
Code: Select all
String itemId = "{DD6E220C-54BC-47B3-8AE8-A0A61D4934FF}".toLowerCase();
CustomXmlDataStoragePart customXmlDataStoragePart = wordMLPackage.getCustomXmlDataStorageParts().get(itemId);


I removed the lines , and references to it in the file and was able to get the output.

But on looking further I tried to figure out the item id and found that the input docx provided for this example has a customxml folder with item xmls. How can i add this while manually creating an input file? When creating the input manually should I follow any process so as to add the items.

This was the input file the example uses
// Convenient to read from .xml file,
// so it is easy to manually edit it (ie without having to unzip etc etc)
// To get the sample file, google for "Content Control Toolkit"
String inputfilepath = "MedicalChartSample.docx";

Re: CustomXMLBinding Example

PostPosted: Fri Mar 30, 2012 8:56 am
by jason
In general, you should get the itemId from the w:databinding element in the content control's w:sdtPr.

If you are using extended custom xml data binding (of the opendope sort, probably created with our Word Add-In), then you can use https://github.com/plutext/OpenDoPE-WAR to merge an XML file into your docx template.

ps, in due course I'll move this post into the sub-forum devoted to this topic

Re: CustomXMLBinding Example

PostPosted: Fri Mar 30, 2012 9:30 pm
by Raj
Thank You. When I created a docx manually I find that the document.xml does not contain the w:databinding element . Can you help me on how to put it into the word docx I create manually.

Re: CustomXMLBinding Example

PostPosted: Fri Mar 30, 2012 10:39 pm
by Raj
Also, I was intending to change the data of an embedded xlxs object.
I was intending to do the following
1) create a docx template with a pie
2) use this as a sample and create a new docx similar to the CustomXMLBinding.java substituting the real values.

I was able to generate the new docx. But I am not sure on how I can make the Chart editable and use the part as is done in the customXMLBinding example.

Re: CustomXMLBinding Example

PostPosted: Fri Mar 30, 2012 10:48 pm
by jason
Use the Add-In from http://www.opendope.org/implementations.html to bind content controls.

There isn't anything in the custom xml data binding to help you create charts, but you can bind a base 64 encoded image (using a picture content control). So you could use JFreeChart say to create a chart, save it as image, base64 encode it, include it in your custom xml, and bind that.