Calling 'GetChildNodes' on nested RichText StructuredDocumentTag nodes generates inconsistent results

When two or more RichText StructuredDocumentTag nodes (SDTs) are nested inside of each other, the number of items returned by ‘GetChildNodes’ is inconsistent.

As an example, I have created the following docx file:

SdtParasTest.docx (20.2 KB)

It has two SDTs: one inside the other, with each containing 2 direct child paragraphs. There is an extra paragraph before the SDTs, and 5 extra paragraphs after.

Performing a deep search for child paragraph nodes appears to return correct results (4 children for the parent SDT, 2 children for the child SDT). However, performing a shallow search is a different story.

For the parent SDT, a shallow paragraph search returns 4 paragraphs as it is incorrectly including the paragraphs of the child SDT. And for the child SDT, a shallow paragraph search returns 7 paragraphs as it is incorrectly including all of the paragraphs that follow the SDTs.

Here is the code I am using:

Document doc = new("SdtParasTest.docx");

// Check the child paragraphs of the parent sdt
IStructuredDocumentTag sdt1 = doc.Range.StructuredDocumentTags[0];
NodeCollection shallowParagraphs1 = sdt1.GetChildNodes(NodeType.Paragraph, false);
Assert.AreEqual(2, shallowParagraphs1.Count); // Fails: returns 4
NodeCollection deepParagraphs1 = sdt1.GetChildNodes(NodeType.Paragraph, true);
Assert.AreEqual(4, deepParagraphs1.Count);

// Check the child paragraphs of the child sdt
IStructuredDocumentTag sdt2 = doc.Range.StructuredDocumentTags[1];
NodeCollection shallowParagraphs2 = sdt2.GetChildNodes(NodeType.Paragraph, false);
Assert.AreEqual(2, shallowParagraphs2.Count); // Fails: returns 7
NodeCollection deepParagraphs2 = sdt2.GetChildNodes(NodeType.Paragraph, true);
Assert.AreEqual(2, deepParagraphs2.Count);

@shaun.stone
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27401

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi, I see the ticket for this one has been marked as closed but I can’t see the ticket number in any recent release notes and the latest version of Aspose.Words still exhibits the problematic behaviour. Is there any update on this one?

@shaun.stone Yes, the issue is already resolved in the current codebase. the fix will be included into the next 24.11 version of Aspose.Words. We will be sure to let you know once it is available.

Much appreciated!

1 Like

The issues you have found earlier (filed as WORDSNET-27401) have been fixed in this Aspose.Words for .NET 24.11 update also available on NuGet.