Text in SDT

Hi,

After running the code below the text in the chosen StructuredDocumentTag did not change in the output file. Instead of “EE1001E: Emerging Technologies in Electrical Engineering” I was expecting to see “New text” when I opened the output file but “EE1001E: Emerging Technologies in Electrical Engineering” was still there. I checked the document.xml and the structure of the output file using Document Explorer and there is only “New text” within the above mentioned StructuredDocumentTag. Could you please check this?

Thanks,

Zeljko

Code:

public void sdtTest() throws Exception {
    String wordDocPath = “SdtInSdt.docx”; 
    Document wordDoc = new Document(wordDocPath);
    StructuredDocumentTag sdt = (StructuredDocumentTag) wordDoc.getChild(NodeType.STRUCTURED_DOCUMENT_TAG, 3, true);
    Paragraph paragraph = (Paragraph) sdt.getFirstChild();
    paragraph.removeAllChildren();
    paragraph.appendChild(new Run(wordDoc, “New text”));
    wordDoc.save(“SdtInSdtSaved.docx”);
}

Hi Zeljko,

Thanks for your inquiry. In your case, you can use the following code:

Document wordDoc = new Document(getMyDir() + “SdtInSdt.docx”);

StructuredDocumentTag oldSdt = (StructuredDocumentTag) wordDoc.getChild(
        NodeType.STRUCTURED_DOCUMENT_TAG, 3, true);
Paragraph paragraph = (Paragraph) oldSdt.getFirstChild().deepClone(true);

StructuredDocumentTag newSdt = new StructuredDocumentTag(wordDoc, oldSdt.getSdtType(), oldSdt.getLevel());
newSdt.setTitle(oldSdt.getTitle());
newSdt.removeAllChildren();
newSdt.appendChild(paragraph);
paragraph.getRuns().get(0).setText(“New Text”);
paragraph.getRuns().get(1).remove();

oldSdt.getParentNode().insertAfter(newSdt, oldSdt);
oldSdt.remove();

wordDoc.save(getMyDir() + “awjava-16.3.0.docx”);

Hope, this helps.

Best regards,

Hi,


Thanks for the solution but unfortunately I cannot use it. It would require major modification to my existing code. Do you maybe know what is wrong with the code I sent you? It works 99% of the time except for the SDT in the attached file. I can clearly see that the text is changed in the output file when I check its XML and the structure of the output file with Document Explorer but when I open it with Microsoft Word old text is still there. Is this a problem with Microsoft Word? I am using 2007, 2010 and 2013 for testing.

Best,
Zeljko

Hi Zeljko,


Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,
Hi Zeljko,

This SDT has w:sdtPr-> w:databinding and will be filled from /ns0:coreProperties[1]/ns1:subject[1]. Unfortunately, data binding of SDT nodes to custom xml packages within a Document is not supported in this version of Aspose.Words. We have logged this problem in our issue tracking system as WORDSNET-13759. Our product team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.

Best regards,

Hi Zeljko,


It is to update you that we have linked your thread to an existing feature request WORDSNET-6284 and will update you as soon as StructuredDocumentTag API version 2 will be released. The SDT API version 2 will provide an API to bind SDT nodes to CustomXML properties.

Best regards,

The issues you have found earlier (filed as WORDSNET-6284) have been fixed in this Aspose.Words for .NET 21.5 update and this Aspose.Words for Java 21.5 update.