Page 1 of 1

CTMarkupRange has no @XmlRootElement

PostPosted: Thu Apr 28, 2011 10:38 pm
by c.hoeflake
Hi,

Since the SVN change 1486, the generation for a simple docx document does not work any longer. I get this exception:

Exception in thread "main" java.lang.RuntimeException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTMarkupRange" as an element because it is missing an @XmlRootElement annotation]
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:530)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:508)
at org.docx4j.model.datastorage.BindingHandler.applyBindings(BindingHandler.java:90)
at Test.main(Test.java:51)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTMarkupRange" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:526)
... 4 more
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTMarkupRange" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:216)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:103)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:141)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:561)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:290)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:103)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:141)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664)
at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:561)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:290)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
... 7 more

could you have a look at this?

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Fri Apr 29, 2011 2:04 am
by jason
Yes, it was intentionally removed since it is more correct that it not be there (since that object relates to from memory 3 XSD elements only one of which is bookmarkEnd).

Please see http://dev.plutext.org/trac/docx4j/brow ... rkAdd.java

for a full example of how to now add bookmarks, but basically the following ought to work:

Code: Select all
                CTMarkupRange mr = factory.createCTMarkupRange();
                mr.setId(ID);
                JAXBElement<CTMarkupRange> bmEnd = factory.createBodyBookmarkEnd(mr);

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Tue May 10, 2011 10:50 am
by davebrown
The removal of @XmlRootElement from CTMarkupRange breaks HTML conversion for certain documents. I see this come out of HtmlExporterNG2 since r1486:

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTMarkupRange" as an element because it is missing an @XmlRootElement annotation]
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:533)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:511)
at org.docx4j.convert.out.html.HtmlExporterNG2.html(HtmlExporterNG2.java:211)

Is there any reason not to keep @XmlRootElement, without a "name" attribute, on CTMarkupRange, so long its derived classes each have a proper @XmlRootElement declaration themselves?

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Wed Jun 01, 2011 12:31 am
by Peter.BY
My application crashes when I try to save the changed docx document that contains bookmarks. Bookmarks were added in Word 2007, not programmatically. Exception is the following:

Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTMarkupRange" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:226)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:267)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:78)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:116)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:571)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:276)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:78)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:116)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:663)
at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:113)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:571)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:276)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:78)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:116)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:663)
at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:113)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:571)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:276)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:472)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:301)
... 16 more
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:334)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:159)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:100)


Is there a workaround for this issue?

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Wed Jun 01, 2011 1:54 am
by jason
I've (temporarily?) reverted the change: http://dev.plutext.org/trac/docx4j/changeset/1515

This should fix the issue for now.

I suspect that the underlying cause is XmlUtils.unwrap. Where that is applied to an object in the object tree which is wrapped in a JAXBElement, that object is unwrapped. That means that JAXB won't know how to handle it, unless it has an @XmlRootElement.

So, what we ought to do is only unwrap if that annotation is present. If that is implemented, then the annotation can be removed from CTMarkupRange again, and if things work properly, left off.

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Wed Jun 01, 2011 5:50 am
by Peter.BY
Looks like there is a relating exception:

Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.FldChar" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:226)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:267)


But in contrast to the CTMarkupRange, the begin and the end of cross-refrence is defined by w:fldCharType attribute of fldChar elements:

<w:fldChar w:fldCharType="begin"/>
<w:fldChar w:fldCharType="end"/>


thus, as I understand, I cannot just add @XmlRootElement? Sorry, if I'm writing stupid things, I have never used JAXB before.

P.S. For me, it is quite an odd way to use xml markup in the way the OOXML does.

Re: CTMarkupRange has no @XmlRootElement

PostPosted: Wed Jun 01, 2011 11:36 pm
by Peter.BY
Please disregard my previous post, I have updated the code and it works good.