Page 1 of 1

Need Help in Repeated Binding

PostPosted: Sun Aug 21, 2011 12:33 am
by linton
Hi All,
I am quite new to docx4j, Though i could succeed in custom xml binding , I am finding difficult in binding repeated rows in a table. The following is the xml (wordprocessingMl) code

Code: Select all
<w:sdt>
            <w:sdtPr>
               <w:alias w:val="Repeat" />
               <w:tag
                  w:val="bindingrole=repeat&amp;w:xpath=/project[1]/authors&amp;w:storeItemID={5C774536-D99F-4F95-B4BC-725DF5804EC0}" />
               <w:id w:val="1418037945" />
            </w:sdtPr>
            <w:sdtContent>
               <w:tr w:rsidR="00E43216" w:rsidTr="001A0211">
                  <w:sdt>
                     <w:sdtPr>
                        <w:id w:val="12962546" />
                        <w:showingPlcHdr />
                        <w:dataBinding w:prefixMappings="xmlns:ns0='http://gsal.project'"
                           w:xpath="/project[1]/authors/author[1]/name" w:storeItemID="{5C774536-D99F-4F95-B4BC-725DF5804EC0}" />
                           <w:alias w:val="Name" />
                <w:tag w:val="name" />
                <w:id w:val="1418037951" />
                <w:placeholder>
                  <w:docPart w:val="DefaultPlaceholder_22675703" />
                </w:placeholder>
                        <w:text />
                     </w:sdtPr>
                     <w:sdtContent>
                        <w:tc>
                           <w:tcPr>
                              <w:tcW w:w="5508" w:type="dxa" />
                           </w:tcPr>
                           <w:p w:rsidR="006C7B17" w:rsidRDefault="001A0211">
                              <w:r>
                                 <w:t>Linton</w:t>
                              </w:r>
                           </w:p>
                        </w:tc>
                     </w:sdtContent>
                  </w:sdt>
                  <w:sdt>
                     <w:sdtPr>
                        <w:id w:val="14802410" />
                        <w:showingPlcHdr />
                        <w:dataBinding w:prefixMappings="xmlns:ns0='http://gsal.project'"
                           w:xpath="/project[1]/authors/author[1]/role" w:storeItemID="{5C774536-D99F-4F95-B4BC-725DF5804EC0}" />
                           <w:alias w:val="Role" />
                <w:tag w:val="role" />
                <w:id w:val="1418037952" />
                <w:placeholder>
                  <w:docPart w:val="DefaultPlaceholder_22675703" />
                </w:placeholder>
                        <w:text />
                     </w:sdtPr>
                     <w:sdtContent>
                        <w:tc>
                           <w:tcPr>
                              <w:tcW w:w="5508" w:type="dxa" />
                           </w:tcPr>
                           <w:p w:rsidR="006C7B17" w:rsidRDefault="001A0211">
                              <w:r>
                                 <w:t>20</w:t>
                              </w:r>
                           </w:p>
                        </w:tc>
                     </w:sdtContent>
                  </w:sdt>
               </w:tr>
            </w:sdtContent>
         </w:sdt>


And this is my customexml data file

Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project xmlns="http://gsal.project" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>TESTING TITTLE</title>
   <authors>
      <author>
         <name>Linton</name>
         <role>20</role>
      </author>
      <author>
         <name>Sam</name>
         <role>Project Manager</role>
      </author>
   </authors>
   <clients>
      <client>
         <name/>
         <type/>
         <passfail/>
         <address/>
         <telephone/>
         <employees>
            <employee>
               <emp_name/>
               <emp_pos/>
            </employee>
         </employees>
      </client>
   </clients>
</project>



I am using the customXMLBinding.java file with smaller modification. It binds only one value in table, fails to repeat.

Can anyone please help to find what i am missing ?


Note:
I am attaching all the files for your reference .. just in case..


Thanks in advance....

Re: Need Help in Repeated Binding

PostPosted: Sun Aug 21, 2011 2:39 am
by jason
You need to "preprocess " repeats and conditionals, by called OpenDoPEHandler, as per the sample ContentControlBindingExtensions.

The symptom of not doing that is that you'll see only the first "row" of data from a repeat.

Hope this helps .. Jason

Re: Need Help in Repeated Binding

PostPosted: Sun Aug 21, 2011 3:59 am
by linton
Hi Jason,
Thanks for your reply. Any clue how preprocess a document and bind with custom xml through code...?



Thank you

Re: Need Help in Repeated Binding

PostPosted: Sun Aug 21, 2011 4:10 am
by linton
I ask that above because..

when i use the following codes
Code: Select all
wordMLPackage = OpenDoPEHandler.preprocess(wordMLPackage);
      wordMLPackage.save(new java.io.File(outputfilepath) );


I am getting the following error which makes me wonder......

OpenDoPE XPaths part missing

Re: Need Help in Repeated Binding

PostPosted: Mon Aug 22, 2011 10:56 pm
by jason
That's right. A docx conforming to the OpenDoPE spec will have that XPaths part. You'd see it in the customXml directory.

Your docx only contains 1 custom xml part (as opposed to 4, which the OpenDoPE Word Add-In adds). Did you create it with the OpenDoPE Word AddIn? Did you subsequently use any other tools on it?

cheers .. Jason

ps I will move this topic to the content controls sub forum in the next day or 2.

Re: Need Help in Repeated Binding

PostPosted: Thu Aug 25, 2011 4:37 am
by linton
Hi Jason,
Thanks again for replying me. I actually got bit more clarified with OpenDoPE. That part was missing in my CustomeXML and in item1.XMl files. I made a little study with the customXML data binding with the invoice.xml file and invoice.docx file which are available in the svn trunk sample docs folder. I could see the table row are repeated. But only three rows, even if i add more child nodes in the xml doc. And when i check inside customXML folder i could see three itemX.xml files.

I am more confused with this. My primary motive is "how to repeat a table row contents?". And latter with nested structure dynamically.

Is it possible Jason ? please give me some clues ..!

Re: Need Help in Repeated Binding

PostPosted: Thu Aug 25, 2011 4:55 am
by linton
Sorry i forgot to mention about the tool i used. I actually doing it manually. So could learn the inside stuffs.............

Re: Need Help in Repeated Binding

PostPosted: Thu Aug 25, 2011 10:39 pm
by jason
Of course the rows should repeat once for each child node.

Are you sure you are processing your template docx through OpenDoPEHandler (which ought to create the necessary rows), and then BindingHandler (which populates the content)?

If so, are you sure about which XML data file you are processing?

By all means create your template docx manually ... but if you are having problems please compare it to the output of the Word Add-In, which should work correctly.

cheers .. Jason