Page 1 of 1

creating contentcontrol

PostPosted: Wed Feb 27, 2013 6:57 am
by fachhoch
I want to try replace placeholder using contentcontrol.

I was able to add contentcontrol by

click on the Developer tab, and identify the Controls group.
Click Design Mode.
Click the Aa button to insert a content control.


Code: Select all
      <w:p>
         <w:r>
            <w:t xml:space="preserve">Mytext   </w:t>
         </w:r>
         <w:sdt>
            <w:sdtPr>
               <w:alias w:val="Data value:placeHolder"/>
               <w:tag w:val="Data value:placeHolder"/>
               <w:id w:val="-888214560"/>
               <w:placeholder>
                  <w:docPart w:val="DefaultPlaceholder_22675703"/>
               </w:placeholder>
               <w:text/>
            </w:sdtPr>
            <w:sdtContent>
               <w:r>
                  <w:t>placeholder</w:t>
               </w:r>
            </w:sdtContent>
         </w:sdt>
      </w:p>



I saw the example ContentControlsXmlEdit

Code: Select all
   WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
      
      // Get the part
      // First we need to get the part.  There are a few different ways to do this.
      
      // If we know the itemId ..
      String itemId = "{5448916C-134B-45E6-B8FE-88CC1FFC17C3}".toLowerCase();
      CustomXmlDataStoragePart customXmlDataStoragePart = wordMLPackage.getCustomXmlDataStorageParts().get(itemId);


in my contentcontrol there is no itemId ?
how can I add the item id please advice.

Re: creating contentcontrol

PostPosted: Wed Feb 27, 2013 7:09 am
by fachhoch
is there any tutorial to create contentcontrol with storeItemId.

I am planning to use content control with storeitemId to replace all my placeholders.

Re: creating contentcontrol

PostPosted: Wed Feb 27, 2013 7:27 am
by fachhoch
I want to create a placeholder with databinding I did not find any examples please advice how can I create a placholder with databindind.

Re: creating contentcontrol

PostPosted: Wed Feb 27, 2013 7:43 am
by jason
See opendope.org,the Getting Started document, or the sub forum.

In summary, there are a couple of tools on codeplex for binding content controls to your XML document.

But docx4j goes further than that, and can use content controls for repeated data, conditional text, and XHTML injection. We call the techniques for doing this the opendope conventions. See the sub-forum for links to authoring tools which are opendope-aware.

Re: creating contentcontrol

PostPosted: Wed Feb 27, 2013 8:48 am
by fachhoch
m goal is to use content controls to replace placeholders. Creating content is eay using word. next I have to figure out how to replace these content controls with actual data using docx4j.

the examples I saw ContentControlsMergeXML,ContentControlsXmlEdit

I want to follow ContentControlsXmlEdit

Code: Select all
      String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/databinding/binding-simple.docx";

      

      // Load the Package
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
      
      // Get the part
      // First we need to get the part.  There are a few different ways to do this.
      
      // If we know the itemId ..
      String itemId = "{5448916C-134B-45E6-B8FE-88CC1FFC17C3}".toLowerCase();
      CustomXmlDataStoragePart customXmlDataStoragePart = wordMLPackage.getCustomXmlDataStorageParts().get(itemId);



here in the above code I dont understand how to get the itemId? I checked the unzip verion of my document and its not present.

Code: Select all
// .. if you don't know the itemId (which you can get using ContentControlsPartsInfo),
      // you could get the part by name, by type,
      // or you could find the item Id by looking in an SDT for w:storeItemID:
      //  <w:sdt>
      //    <w:sdtPr>
      //      <w:dataBinding w:prefixMappings="" w:xpath="/myxml[1]/element1[1]"
      //               w:storeItemID="{5448916C-134B-45E6-B8FE-88CC1FFC17C3}"/>
      //    </w:sdtPr>
      //    <w:sdtContent>      
      
      // Get the contents      


(or you could find the item Id by looking in an SDT for w:storeItemID:) its not in the document.xml

so the second approach is to you could get the part by name, by type any examples on this?

all the core part of replacing lies in this
Code: Select all
CustomXmlDataStorage customXmlDataStorage = customXmlDataStoragePart.getData();

((CustomXmlDataStorageImpl)customXmlDataStorage).setNodeValueAtXPath("/myxml/element1", example_value_to_inject,
            "xmlns:ns0='http://your.namespace'");

but my problem is I dont know how to get customXmlDataStorage instance, as I dont know how to get CustomXmlDataStoragePart , please help me

here is my document.xml

Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
   <w:body>
      <w:p>
         <w:pPr>
            <w:pStyle w:val="SigBox"/>
            <w:tabs>
               <w:tab w:val="clear" w:pos="4320"/>
               <w:tab w:val="clear" w:pos="8640"/>
            </w:tabs>
            <w:jc w:val="center"/>
            <w:rPr>
               <w:b/>
               <w:szCs w:val="24"/>
               <w:u w:val="single"/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:b/>
               <w:szCs w:val="24"/>
               <w:u w:val="single"/>
            </w:rPr>
            <w:t>CERTIFIED MAIL - RETURN RECEIPT REQUESTED</w:t>
         </w:r>
      </w:p>
      <w:sdt>
         <w:sdtPr>
            <w:rPr>
               <w:szCs w:val="24"/>
            </w:rPr>
            <w:id w:val="-889017388"/>
            <w:placeholder>
               <w:docPart w:val="EDCA2E64CFCD4F488D76F03E8327CACD"/>
            </w:placeholder>
            <w:text/>
         </w:sdtPr>
         <w:sdtContent>
            <w:p>
               <w:pPr>
                  <w:pStyle w:val="SigBox"/>
                  <w:tabs>
                     <w:tab w:val="clear" w:pos="4320"/>
                     <w:tab w:val="clear" w:pos="8640"/>
                  </w:tabs>
                  <w:ind w:left="2880" w:firstLine="720"/>
                  <w:rPr>
                     <w:sz w:val="22"/>
                     <w:szCs w:val="22"/>
                  </w:rPr>
               </w:pPr>
               <w:r>
                  <w:rPr>
                     <w:sz w:val="22"/>
                     <w:szCs w:val="22"/>
                  </w:rPr>
                  <w:t xml:space="preserve"/>
               </w:r>
               <w:proofErr w:type="gramStart"/>
               <w:r>
                  <w:rPr>
                     <w:sz w:val="22"/>
                     <w:szCs w:val="22"/>
                  </w:rPr>
                  <w:t>facIdentificationNumber</w:t>
               </w:r>
               <w:proofErr w:type="gramEnd"/>
            </w:p>
         </w:sdtContent>
      </w:sdt>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:highlight w:val="yellow"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:sdt>
         <w:sdtPr>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:b/>
            </w:rPr>
            <w:tag w:val="adl/transmittalLetterDate"/>
            <w:id w:val="-885164104"/>
            <w:placeholder>
               <w:docPart w:val="EDCA2E64CFCD4F488D76F03E8327CACD"/>
            </w:placeholder>
            <w:text/>
         </w:sdtPr>
         <w:sdtContent>
            <w:p>
               <w:pPr>
                  <w:spacing w:after="0"/>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                     <w:b/>
                  </w:rPr>
               </w:pPr>
               <w:proofErr w:type="gramStart"/>
               <w:r>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                     <w:b/>
                  </w:rPr>
                  <w:t>transmittalLetterDate</w:t>
               </w:r>
               <w:proofErr w:type="gramEnd"/>
            </w:p>
         </w:sdtContent>
      </w:sdt>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:highlight w:val="yellow"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:sdt>
         <w:sdtPr>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
            <w:tag w:val="adl/granteeName"/>
            <w:id w:val="-885164123"/>
            <w:placeholder>
               <w:docPart w:val="EDCA2E64CFCD4F488D76F03E8327CACD"/>
            </w:placeholder>
            <w:text/>
         </w:sdtPr>
         <w:sdtContent>
            <w:p>
               <w:pPr>
                  <w:spacing w:after="0"/>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                  </w:rPr>
               </w:pPr>
               <w:proofErr w:type="gramStart"/>
               <w:r>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                  </w:rPr>
                  <w:t>granteeName</w:t>
               </w:r>
               <w:proofErr w:type="gramEnd"/>
            </w:p>
         </w:sdtContent>
      </w:sdt>
      <w:sdt>
         <w:sdtPr>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
            <w:tag w:val="adl/granteeAddress"/>
            <w:id w:val="-885164106"/>
            <w:placeholder>
               <w:docPart w:val="EDCA2E64CFCD4F488D76F03E8327CACD"/>
            </w:placeholder>
            <w:text/>
         </w:sdtPr>
         <w:sdtContent>
            <w:p>
               <w:pPr>
                  <w:spacing w:after="0"/>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                  </w:rPr>
               </w:pPr>
               <w:proofErr w:type="gramStart"/>
               <w:r>
                  <w:rPr>
                     <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
                  </w:rPr>
                  <w:t>granteeAddress</w:t>
               </w:r>
               <w:proofErr w:type="gramEnd"/>
            </w:p>
         </w:sdtContent>
      </w:sdt>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
            <w:t xml:space="preserve"/>
         </w:r>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:ind w:left="720"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
            <w:t>In accordance with 45 CFR 98.66(f), you may request reconsideration by the Assistant Secretary.  A request for reconsideration will not preclude your right to a subsequent appeal.  Your written request for reconsideration by the Assistant Secretary must be made within 30 days of the date of this letter, and must include a copy of this disallowance letter, and be sent to:</w:t>
         </w:r>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:ind w:left="720"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
            <w:t>In accordance with 45 CFR 98.66(f), you may request reconsideration by the Assistant Secretary.  A request for reconsideration will not preclude your right to a subsequent appeal.  Your written request for reconsideration by the Assistant Secretary must be made within 30 days of the date of this letter, and must include a copy of this disallowance letter, and be sent to:</w:t>
         </w:r>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:ind w:left="720"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
         </w:pPr>
         <w:r>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
               <w:noProof/>
            </w:rPr>
            <w:t>In accordance with 45 CFR 98.66(f), you may request reconsideration by the Assistant Secretary.  A request for reconsideration will not preclude your right to a subsequent appeal.  Your written request for reconsideration by the Assistant Secretary must be made within 30 days of the date of this letter, and must include a copy of this disallowance letter, and be sent to:</w:t>
         </w:r>
      </w:p>
      <w:p>
         <w:pPr>
            <w:spacing w:after="0"/>
            <w:rPr>
               <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
            </w:rPr>
         </w:pPr>
      </w:p>
      <w:p/>
      <w:sectPr>
         <w:pgSz w:w="12240" w:h="15840"/>
         <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
         <w:cols w:space="720"/>
         <w:docGrid w:linePitch="360"/>
      </w:sectPr>
   </w:body>
</w:document>

Re: creating contentcontrol

PostPosted: Wed Feb 27, 2013 9:22 am
by jason
Each custom xml part has a store Item ID (stored in a related part)

A data bound content control specifies store Item ID in its data binding element.

So that's how the 2 are tied together.

But you typically don't need to worry about this.

Template design step: You set up the content control data bindings using an authoring tool

At runtime: You provide the XML data to docx4j, and it does the rest.