We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

CompositeNode.GetChildNodes Returns Incorrect Number of Tables using .NET

I have a file with only three tables in it. I get six tables by using my code and two methods,But open the file with DocumentExplorer Demo for Aspose.Words , and there are three tables in it.
my code

Node[] tables = doc.Body.GetChildNodes(NodeType.Table, true).ToArray();
NodeCollection tables1 = doc.GetChildNodes(NodeType.Table, true);
return result:tables.count=6,tables1.count=6

I have two questions:
1、How does this DocumentExplorer Demo open a file and get the table in it
2、my code tables[1].PreviousSibling is null?In fact, he has a previous paragraph

test.Docx (30.3 KB)
Uploading: test.jpg(3)…


There are nested table in the last row of first table. Please check the attached DOM image for detail. DOM.png (46.2 KB)

You can also change the table’s border color to identify nested tables as shown below.

Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "test.docx");
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
    if (table.ParentNode.NodeType == NodeType.Cell)
        table.SetBorders(LineStyle.Dot, 1, Color.Blue);
        table.SetBorders(LineStyle.Dot, 1, Color.Red);
doc.Save(MyDir + "21.7.docx");

In your document, the nested table has no previous siblings. You can check the second table (with 1 index) as shown below.

Node[] tables = doc.GetChildNodes(NodeType.Table, true).ToArray();
Table table = (Table)tables[1];
if (table.ParentNode.NodeType == NodeType.Cell)
    Console.WriteLine("This is nested table in the table's cell");