Page 1 of 1

Binding Condition control over table

PostPosted: Fri May 19, 2017 2:24 am
by alister
I have error when using od:condition placed over table row.
In case the same od:condition is placed over single text it is working fine.
The error is
Code: Select all
18:06:23,493 ERROR [org.docx4j.model.datastorage.BindingTraverserState:63] (http-/172.31.0.43:8080-9:) - unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"tc"). Expected elements are <{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdt>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}del>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeStart>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMathPara>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFrom>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeStart>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMath>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXml>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ins>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveTo>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}proofErr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tr>
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"tc"). Expected elements are <{http://schemas.openxmlformats.org/wordprocessingml/2006/main}sdt>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}permStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}del>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeStart>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMathPara>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFrom>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlDelRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveToRangeStart>,<{http://schemas.openxmlformats.org/officeDocument/2006/math}oMath>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveFromRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXml>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlInsRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ins>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}customXmlMoveFromRangeStart>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}commentRangeEnd>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}moveTo>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}proofErr>,<{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tr>

Re: Binding Condition control over table

PostPosted: Fri May 19, 2017 2:48 am
by alister
Seems that condition works over table and does not work over table row

Re: Binding Condition control over table

PostPosted: Fri May 19, 2017 9:41 am
by jason
Please post the relevant XML.

That error is saying the expected content is a table row (tr), but a tc was encountered.

Re: Binding Condition control over table

PostPosted: Fri May 19, 2017 7:24 pm
by alister
Thenk you for the reply, Jason.
Xml parts of the docx file are attached. Here is the code fragment of document.xml
Code: Select all
    <w:body>
        <w:tbl>
            <w:tblPr>
                <w:tblStyle w:val="a8"/>
                <w:tblW w:type="auto" w:w="0"/>
                <w:tblLook w:firstColumn="1" w:firstRow="1" w:lastColumn="0" w:lastRow="0" w:noHBand="0" w:noVBand="1" w:val="04A0"/>
            </w:tblPr>
            <w:tblGrid>
                <w:gridCol w:w="4927"/>
                <w:gridCol w:w="4928"/>
            </w:tblGrid>
            <w:tr>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:type="dxa" w:w="4927"/>
                    </w:tcPr>
                    <w:sdt>
                        <w:sdtPr>
                            <w:rPr>
                                <w:sz w:val="28"/>
                                <w:szCs w:val="28"/>
                                <w:lang w:val="en-US"/>
                            </w:rPr>
                            <w:tag w:val="od:xpath=c1f1"/>
                            <w:id w:val="1810825354"/>
                            <w:placeholder>
                                <w:docPart w:val="913BA8A6BF0B42449AD0B742E2C4724E"/>
                            </w:placeholder>
                            <w:showingPlcHdr/>
                            <w:dataBinding w:storeItemID="{566A1552-D930-4302-A416-2580F1A7FFEC}" w:xpath="/report/subconts1/subcont1/Field1"/>
                            <w:text/>
                        </w:sdtPr>
                        <w:sdtContent>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:sz w:val="28"/>
                                        <w:szCs w:val="28"/>
                                        <w:lang w:val="en-US"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rStyle w:val="a9"/>
                                    </w:rPr>
                                    <w:t>Место для ввода текста.</w:t>
                                </w:r>
                            </w:p>
                        </w:sdtContent>
                    </w:sdt>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:type="dxa" w:w="4928"/>
                    </w:tcPr>
                    <w:p>
                        <w:pPr>
                            <w:rPr>
                                <w:sz w:val="28"/>
                                <w:szCs w:val="28"/>
                            </w:rPr>
                        </w:pPr>
                    </w:p>
                </w:tc>
            </w:tr>
            <w:sdt>
                <w:sdtPr>
                    <w:rPr>
                        <w:sz w:val="28"/>
                        <w:szCs w:val="28"/>
                        <w:lang w:val="en-US"/>
                    </w:rPr>
                    <w:tag w:val="od:condition=cond1"/>
                    <w:id w:val="-453634326"/>
                    <w:placeholder>
                        <w:docPart w:val="913BA8A6BF0B42449AD0B742E2C4724E"/>
                    </w:placeholder>
                </w:sdtPr>
                <w:sdtContent>
                    <w:tr>
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:type="dxa" w:w="4927"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:sz w:val="28"/>
                                        <w:szCs w:val="28"/>
                                        <w:lang w:val="en-US"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="28"/>
                                        <w:szCs w:val="28"/>
                                        <w:lang w:val="en-US"/>
                                    </w:rPr>
                                    <w:t>Field1</w:t>
                                </w:r>
                            </w:p>
                        </w:tc>
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:type="dxa" w:w="4928"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:sz w:val="28"/>
                                        <w:szCs w:val="28"/>
                                        <w:lang w:val="en-US"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="28"/>
                                        <w:szCs w:val="28"/>
                                        <w:lang w:val="en-US"/>
                                    </w:rPr>
                                    <w:t>Field2</w:t>
                                </w:r>
                            </w:p>
                        </w:tc>
                    </w:tr>
                </w:sdtContent>
            </w:sdt>
            <w:tr>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:type="dxa" w:w="4927"/>
                    </w:tcPr>
                    <w:p>
                        <w:pPr>
                            <w:rPr>
                                <w:sz w:val="28"/>
                                <w:szCs w:val="28"/>
                            </w:rPr>
                        </w:pPr>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:type="dxa" w:w="4928"/>
                    </w:tcPr>
                    <w:p>
                        <w:pPr>
                            <w:rPr>
                                <w:sz w:val="28"/>
                                <w:szCs w:val="28"/>
                            </w:rPr>
                        </w:pPr>
                    </w:p>
                </w:tc>
            </w:tr>
        </w:tbl>
        <w:p/>
        <w:sectPr>
            <w:pgSz w:h="15840" w:w="12240"/>
            <w:pgMar w:bottom="850" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="850" w:top="850"/>
            <w:cols w:space="720"/>
        </w:sectPr>

Re: Binding Condition control over table

PostPosted: Mon May 22, 2017 10:03 pm
by jason
At a glance the XML looks OK. Can you post the input docx + data xml, or email it to me, and I'll try it myself.

Re: Binding Condition control over table

PostPosted: Tue May 30, 2017 2:22 am
by alister
Sorry for delay, the docx and xml are attached

Re: Binding Condition control over table

PostPosted: Tue May 30, 2017 11:22 pm
by jason
Running your files through the ContentControlBindingExtensions sample, using https://www.docx4java.org/docx4j/docx4j ... 170527.jar
I don't see that error:

Code: Select all
INFO org.docx4j.jaxb.Context .<clinit> line 86 - java.vendor=Oracle Corporation
INFO org.docx4j.jaxb.Context .<clinit> line 87 - java.version=1.8.0_05
INFO org.docx4j.jaxb.Context .<clinit> line 111 - No MOXy JAXB config found; assume not intended..
INFO org.docx4j.jaxb.NamespacePrefixMapperUtils .getPrefixMapper line 75 - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
INFO org.docx4j.jaxb.Context .<clinit> line 120 - Using Java 6/7 JAXB implementation
INFO org.docx4j.jaxb.Context .<clinit> line 166 - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
INFO org.docx4j.openpackaging.contenttype.ContentTypeManager .createPackage line 864 - Detected WordProcessingML package
INFO org.docx4j.openpackaging.io3.Load3 .get line 160 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
WARN org.docx4j.openpackaging.io3.Load3 .getRawPart line 541 - No JAXB model for this CustomXmlDataStorage part; null
INFO org.docx4j.openpackaging.io3.Load3 .get line 179 - package read;  elapsed time: 111 ms
DEBUG org.docx4j.model.datastorage.CustomXmlDataStoragePartSelector .getCustomXmlDataStoragePart line 95 - Attempting to use item id: {566a1552-d930-4302-a416-2580f1a7ffec}
DEBUG org.docx4j.model.datastorage.CustomXmlDataStoragePartSelector .getCustomXmlDataStoragePart line 109 - Using {566A1552-D930-4302-A416-2580F1A7FFEC}
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .<init> line 103 - <odx:xpaths  xmlns:odx="http://opendope.org/xpaths" >
    <odx:xpath id="c1f1">
        <odx:dataBinding xpath="/report/subconts1/subcont1/Field1" storeItemID="{566A1552-D930-4302-A416-2580F1A7FFEC}"/>
    </odx:xpath>
    <odx:xpath id="xcond1">
        <odx:dataBinding xpath="/report/subconts/subcont1" storeItemID="{566A1552-D930-4302-A416-2580F1A7FFEC}"/>
    </odx:xpath>
</odx:xpaths>
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .<init> line 121 - <odc:conditions  xmlns:odc="http://opendope.org/conditions" >
    <odc:condition id="cond1">
        <odc:xpathref id="xcond1"/>
    </odc:condition>
</odc:conditions>
:
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .processBindingRoleIfAny line 761 - Processing -453634326
INFO org.docx4j.model.datastorage.OpenDoPEHandler .processBindingRoleIfAny line 772 - od:condition=cond1
INFO org.docx4j.model.datastorage.OpenDoPEHandler .processBindingRoleIfAny line 790 - Processing Conditional: od:condition=cond1
DEBUG org.docx4j.model.datastorage.BindingHandler .xpathGetString line 297 - /report/subconts/subcont1 with null
DEBUG org.docx4j.model.datastorage.BindingHandler .xpathGetString line 333 - /report/subconts/subcont1 yielded result 'false'
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .processBindingRoleIfAny line 807 - false
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .walkJAXBElements line 710 - no children: org.docx4j.wml.Text
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .walkJAXBElements line 710 - no children: org.docx4j.wml.CTBookmark
DEBUG org.docx4j.model.datastorage.OpenDoPEHandler .walkJAXBElements line 710 - no children: org.docx4j.wml.CTMarkupRange
INFO org.docx4j.model.datastorage.OpenDoPEIntegrity .process line 133 - /n Processing /word/document.xml
method: xml
INFO org.docx4j.model.datastorage.BindingHandler .applyBindings line 252 - Using BindingTraverserXSLT, which is slower, but fully featured
DEBUG org.docx4j.model.datastorage.CustomXmlDataStoragePartSelector .getCustomXmlDataStoragePart line 95 - Attempting to use item id: {566a1552-d930-4302-a416-2580f1a7ffec}
DEBUG org.docx4j.model.datastorage.CustomXmlDataStoragePartSelector .getCustomXmlDataStoragePart line 109 - Using {566A1552-D930-4302-A416-2580F1A7FFEC}
DEBUG org.docx4j.model.datastorage.DomToXPathMap .walkTree line 70 - child 0of DOCUMENT_NODE
DEBUG org.docx4j.model.datastorage.BindingTraverserXSLT .traverseToBind line 166 - Mapped 77 in 2ms
method: xml
DEBUG org.docx4j.model.datastorage.BindingTraverserXSLT .xpathGenerateRuns line 822 - Looking for xpath with id: c1f1 referenced from part /word/document.xml at od:xpath=c1f1
DEBUG org.docx4j.model.datastorage.BindingTraverserXSLT .xpathGenerateRuns line 924 - cache miss for /report/subconts1/subcont1/Field1
DEBUG org.docx4j.model.datastorage.BindingHandler .xpathGetString line 297 - /report/subconts1/subcont1/Field1 with null
DEBUG org.docx4j.model.datastorage.BindingHandler .xpathGetString line 329 - XML element is missing (or empty) for xpath: /report/subconts1/subcont1/Field1
INFO org.docx4j.model.datastorage.BindingTraverserXSLT .xpathGenerateRuns line 941 - /report/subconts1/subcont1/Field1
yielded result ''
WARN org.docx4j.utils.ResourceUtils .getResource line 96 - Couldn't get resource: OpenDoPE/placeholder.xml
WARN org.docx4j.utils.ResourceUtils .getResourceViaProperty line 52 - OpenDoPE/placeholder.xml: OpenDoPE/placeholder.xml not found via classloader.
WARN org.docx4j.utils.ResourceUtils .getResourceViaProperty line 55 - Property docx4j.model.datastorage.placeholder resolved to missing resource OpenDoPE/placeholder.xml; using OpenDoPE/placeholder.xml
WARN org.docx4j.utils.ResourceUtils .getResource line 96 - Couldn't get resource: OpenDoPE/placeholder.xml
INFO org.docx4j.model.datastorage.BindingTraverserXSLT .createPlaceholderFragment line 330 - No resource on classpath for property docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml
WARN org.docx4j.utils.ResourceUtils .getResource line 96 - Couldn't get resource: OpenDoPE/placeholder.xml
WARN org.docx4j.utils.ResourceUtils .getResourceViaProperty line 52 - OpenDoPE/placeholder.xml: OpenDoPE/placeholder.xml not found via classloader.
WARN org.docx4j.utils.ResourceUtils .getResourceViaProperty line 55 - Property docx4j.model.datastorage.placeholder resolved to missing resource OpenDoPE/placeholder.xml; using OpenDoPE/placeholder.xml
WARN org.docx4j.utils.ResourceUtils .getResource line 96 - Couldn't get resource: OpenDoPE/placeholder.xml
INFO org.docx4j.model.datastorage.BindingTraverserXSLT .createPlaceholderBytes line 346 - No resource on classpath at docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml
INFO org.docx4j.model.datastorage.BindingTraverserXSLT .log line 220 - [String] od:xpath=c1f1
INFO org.docx4j.model.datastorage.BindingTraverserXSLT .log line 220 - [String]  processing contents only of od:resultConditionFalse=cond1
method: xml
INFO org.docx4j.jaxb.NamespacePrefixMapperUtils .getPrefixMapperRelationshipsPart line 136 - Using NamespacePrefixMapperRelationshipsPartSunInternal, which is suitable for Java 6
Saved: C:\Users\jharrop\git\plutext\docx4jGREAT/OUT_ContentControlsMergeXML.docx

Re: Binding Condition control over table

PostPosted: Wed May 31, 2017 9:39 pm
by alister
I checked binding with docx4j-nightly-20170527.jar, it is really working with no error. The error was in version 3.3.1.
I am using maven repository and only version 3.3.1 for docx4j-export-fo is available there.
If there is no other way out, I will use docx4j-nightly-20170527.jar from my local repository instead of docx4j-3.3.1.jar from maven repository....
Code: Select all
<dependency>
     <groupId>org.docx4j</groupId>
     <artifactId>docx4j-export-fo</artifactId>
     <version>3.3.1</version>
</dependency>
<dependency>
       <groupId>org.docx4j</groupId>
       <artifactId>docx4j-ImportXHTML</artifactId>
       <version>3.3.1</version>
</dependency>

Re: Binding Condition control over table

PostPosted: Wed May 31, 2017 9:54 pm
by jason
You could try docx4j 3.3.3: http://search.maven.org/#artifactdetail ... .3.3%7Cjar

It ought to work with export-fo 3.3.1.

But docx4j-nightly-20170527.jar does fix some binding stuff (compared to 3.3.3). I hope to get 3.3.4 out soon.

Re: Binding Condition control over table

PostPosted: Wed May 31, 2017 10:52 pm
by alister
Well, I have tried docx4j-export-fo 3.3.1 with docx4j 3.3.3, but it is better with night build.
There is still one error in log after binding, which persists even in night build:

14:16:29,404 WARN [org.docx4j.model.styles.StyleTree:126] (http-/172.31.0.43:8080-1:) - Couldn't find style: PlaceholderText
14:16:29,404 WARN [org.docx4j.model.styles.StyleTree:150] (http-/172.31.0.43:8080-1:) - Couldn't find style: PlaceholderText

There is no style PlaceholderText in original docx template, in its style.xml
But after binding there is style PlaceholderText in document.xml and it is still not present in style.xml
fragment from document.xml in template
Code: Select all
                  <w:sdt>
                     <w:sdtPr>
                        <w:alias w:val="whomValue"/>
                        <w:tag w:val="od:xpath=cont1f2"/>
                        <w:id w:val="-388042734"/>
                        <w:placeholder>
                           <w:docPart w:val="5F8899884BF94150A9499AC4878462F7"/>
                        </w:placeholder>
                        <w:showingPlcHdr/>
                        <w:dataBinding w:xpath="/report[1]/subconts1/subcont1[1]/Field2" w:storeItemID="{86FA683F-2B26-4E50-8B43-4D05F3EF5AC2}"/>
                        <w:text/>
                     </w:sdtPr>
                     <w:sdtContent>
                        <w:tc>
                           <w:tcPr>
                              <w:tcW w:w="8022" w:type="dxa"/>
                              <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                           </w:tcPr>
                           <w:p>
                              <w:pPr>
                                 <w:spacing w:after="0"/>
                                 <w:ind w:firstLine="12"/>
                              </w:pPr>
                              <w:r>
                                 <w:rPr>
                                    <w:rStyle w:val="a9"/>
                                    <w:color w:val="auto"/>
                                 </w:rPr>
                                 <w:t>Место для ввода текста.</w:t>
                              </w:r>
                           </w:p>
                        </w:tc>
                     </w:sdtContent>
                  </w:sdt>

And the same part after binding
Code: Select all
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="8022" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                    </w:tcPr>
                    <w:p>
                        <w:pPr>
                            <w:spacing w:after="0"/>
                            <w:ind w:firstLine="12"/>
                        </w:pPr>
                        <w:r>
                            <w:rPr>
<w:rStyle w:val="PlaceholderText"/>
                            </w:rPr>
                            <w:t> </w:t>
                        </w:r>
                    </w:p>
                </w:tc>

Re: Binding Condition control over table

PostPosted: Thu Jun 01, 2017 7:16 pm
by alister
Also word\styles.xml of the original template docx file added