Free Support Forum - aspose.com

SDT Reading Issue

Attached document for reference:
Redacted.zip (51.6 KB)

The document contains special SDTs which are having Title “redacted”. But the issue I am facing is

  1. The document contains 5 SDTs which are having Title “redacted”. But when I am traversing through them it is providing me 6 SDTs with Title “redacted”.
  2. When I am reading text from sdt using sdt.Range.Text it is returning text with escape sequences like ‘/w/r’. Is there any way by which I can get only plain text from Range?
    The code I am using is

NodeCollection nodes = LobjDocument.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (StructuredDocumentTag sdt in nodes)
{
if(sdt.Title.Trim() == “redacted”)
{
Debug.WriteLine(sdt.Range.Text);
Debug.WriteLine(sdt.Tag);
}
}

@mhtsharma9,

Thanks for your inquiry. After an initial test with the licensed latest version of Aspose.Words for .NET i.e. 18.8, we were unable to reproduce this issue on our end. The code returns five SDT tags. So, we would suggest you please upgrade to the latest version of Aspose.Words for .NET. Hope, this helps.

Secondly to get the text of SDT, please use the following code:

NodeCollection nodes = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (StructuredDocumentTag sdt in nodes)
{
    if (sdt.Title.Trim() == "redacted")
    {
        Debug.WriteLine(sdt.ToString(SaveFormat.Text));
    }
}

Using 18.8 of Aspose.Words for .NET is also not helping.
I am still getting 6 redacted componenets in above document.
And
sdt.ToString(SaveFormat.Text) is stillgiving escape sequences in Text.

And one of the component is showing me page no 0 (this is the component which is showing twice to me)

@mhtsharma9,

We have generated a Word document (see 18.8.zip (5.5 KB)) by using the following code:

Document doc = new Document("D:\\Temp\\Redacted\\Redacted.docx");

DocumentBuilder builder = new DocumentBuilder();

NodeCollection nodes = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (StructuredDocumentTag sdt in nodes)
{
    if (sdt.Title.Trim() == "redacted")
    {
        builder.Font.Bold = true;
        builder.Writeln("SDT TAG: " + sdt.Tag);

        builder.Font.Bold = false;
        builder.Writeln(sdt.ToString(SaveFormat.Text));


        builder.InsertHtml("<hr/>");
    }
}

builder.Document.Save("D:\\temp\\Redacted\\18.8.docx");

You can see that it shows data of only five SDT controls.

Please also create a screenshot highlighting (encircle) all the problematic areas in above Aspose.Words generated output Word document that you do not want to see and share the screenshot here for our reference.