Page 1 of 1

[FIXED] invalid .xml files with svn tip

PostPosted: Wed Feb 23, 2011 9:23 pm
by Siempre
I am trying to get docx4j to work for me to create Resumes based on a template.
I adapted an existing resume and added content-control.
The first time I ran the ContentControlBindingExtension example using my files I got an exception stating that CTSmartTagRun did not have the @XmlRootElement annotation.
So I downloaded the source, added the annotation (@XmlRootElement(name = "CTSmartTagRun")) to the CTSmartTagRun.java class and rebuild the jar.

Than I ran the example again and this time it succeeded.
The only problem is that the generated files are invalid, meaning that Word cannot open them. I can open them in an xml editor and see the xml.
Maybe the problem is with adding an incorrect @XmlRootElement or my template is incorrect.

*Also the repeat for bulletpoints doesn't seem to work either, but I haven't looked into taht in great detail so it could be I just setup the template incorrect.

Anyway here are the files I am using, hopefully you can help me out.

http://dl.dropbox.com/u/4339608/docx/CV ... imple.docx : This is the template with only a plain text control
http://dl.dropbox.com/u/4339608/docx/CV ... cessed.xml : The preprocessed version
http://dl.dropbox.com/u/4339608/docx/CV ... cessed.xml : The processed version
http://dl.dropbox.com/u/4339608/docx/CV_bound_nons.docx : Thsi is the template with a plain text control and a repeat for a bullet list
http://dl.dropbox.com/u/4339608/docx/CV ... cessed.xml : The preprocessed version
http://dl.dropbox.com/u/4339608/docx/CV ... cessed.xml : The processed version

Re: Content control binding creates invalid files

PostPosted: Wed Feb 23, 2011 10:54 pm
by jason
Siempre wrote:The first time I ran the ContentControlBindingExtension example using my files I got an exception stating that CTSmartTagRun did not have the @XmlRootElement annotation.
So I downloaded the source, added the annotation (@XmlRootElement(name = "CTSmartTagRun")) to the CTSmartTagRun.java class and rebuild the jar.

Than I ran the example again and this time it succeeded.
The only problem is that the generated files are invalid, meaning that Word cannot open them. I can open them in an xml editor and see the xml.
Maybe the problem is with adding an incorrect @XmlRootElement or my template is incorrect


Yes, try @XmlRootElement(name = "smartTag") since this is what is in your document:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
            <w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="country-region">
              <w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="place">
                <w:r w:rsidR="009F10BC" w:rsidRPr="00455D09">
                  <w:rPr>
                    <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
                    <w:color w:val="auto"/>
                    <w:sz w:val="22"/>
                    <w:szCs w:val="22"/>
                  </w:rPr>
                  <w:t>Belgium</w:t>
                </w:r>
              </w:smartTag>
            </w:smartTag>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I've checked the schema; this is a safe thing to do.

ps I will move this post into the databinding sub-forum in a day or two.

Re: Content control binding creates invalid files

PostPosted: Wed Feb 23, 2011 11:15 pm
by Siempre
Thanks for the quick reply.
I tried that but it makes no difference.
But I noticed something else. Processing your invoice.docx file now also results in an invalid file. Or at least I am unable to open them. It worked yesterday when I ran the example and now it doesn't seem to work anymore.

http://dl.dropbox.com/u/4339608/docx/invoice.docx : My version of you invoice.docx
http://dl.dropbox.com/u/4339608/docx/in ... cessed.xml : The preprocessed version
http://dl.dropbox.com/u/4339608/docx/in ... cessed.xml : The processed version

i am going to try to setup my environment from scratch to see if I can get your example to work again.

Re: Content control binding creates invalid files

PostPosted: Wed Feb 23, 2011 11:38 pm
by jason
OK, let me know how you go. I won't look at your files until I hear back from you...

Re: Content control binding creates invalid files

PostPosted: Thu Feb 24, 2011 12:26 am
by Siempre
Ok so,

I created a new environment from scratch and downloaded the current nightly build and downloaded the invoice.docx and ContentControlBindingExtensions.java again.
I set it up and ran the example resulting in a valid document.
I then replaced the docx4j-2.6.0.jar by the one I created with the @XmlRootElement annotation added in CTSmartTagRun.java.
This was created by using the source code from the svn checkout and using the maven build included.

Now It once again creates invalid files.
Could there be something wrong with the current version in svn?

Edit: I also created the development environment again from scratch (using the eclipse way described on the website).
And when using the jar created by using mvn install (without having made any adjustements), the example also creates invalid files with the invoice.docx.

Edit2: The files created with the build created from the source in svn are aprox. 2 KB smaller than the ones created with the nightly dist.

Re: Content control binding creates invalid files

PostPosted: Thu Feb 24, 2011 4:10 pm
by jason
The problem you experienced was a regression in FlatOpcExporter, which produces the .xml file. (Things would have worked fine if you were saving as docx instead).

The regression was introduced 3 weeks ago, and is now fixed: http://dev.plutext.org/trac/docx4j/changeset/1439

Thanks for alerting me to this.

Re: Content control binding creates invalid files

PostPosted: Thu Feb 24, 2011 7:27 pm
by Siempre
Thanks!

This indeed fixes it.
Saving in docx format also worked anyway just like you said.

Now I can go and concentrate on why the repeat isn't working.