just posting some details and clarifications.
the content control is created like this:
- Code: Select all
protected SdtRun createContentControl(String key, String xpath, String storeItemID) {
SdtRun sdtRun = Context.getWmlObjectFactory().createSdtRun();
SdtPr sdtPr = Context.getWmlObjectFactory().createSdtPr();
sdtRun.setSdtPr(sdtPr);
/*
<w:sdtPr>
<w:tag w:val="od:xpath=my-xpath-id"/>
<w:id w:val="-1442757830"/>
<w:placeholder>
<w:docPart w:val="DefaultPlaceholder_1082065158"/>
</w:placeholder>
<w:dataBinding w:xpath="/MyXml/Duck[1]/@name" w:storeItemID="{6756DA53-8ADB-416F-97AD-557680F6F030}"/>
<w:text/>
</w:sdtPr>
*/
Tag tag = Context.getWmlObjectFactory().createTag();
tag.setVal("od:xpath=" + key);
sdtPr.setTag(tag);
sdtPr.setId();
CTDataBinding ctDataBinding = Context.getWmlObjectFactory().createCTDataBinding();
JAXBElement<CTDataBinding> jaxbDB = Context.getWmlObjectFactory().createSdtPrDataBinding(ctDataBinding);
sdtPr.setDataBinding(ctDataBinding);
ctDataBinding.setXpath(xpath);
ctDataBinding.setStoreItemID(storeItemID);
CTSdtContentRun sdtContent = Context.getWmlObjectFactory().createCTSdtContentRun();
sdtRun.setSdtContent(sdtContent);
return sdtRun;
}
which is called like this
- Code: Select all
SdtRun sdt = createContentControl("my-xpath-id", "/MyXml/Duck[1]/@name", storeItemID);
mainDocumentPart.addObject(sdt);
i did not find any way to add new xPaths to the XPathsPart returned by mainDocumentPart.getXPathsPart()