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

Free Support Forum - aspose.com

How to read a word document based on node type in sequence


In my attached sample document is having paragraph, Image,paragraph,Table,Paragraph. I am not able to read these elements in sequence as in my source document.Bellow is my code,

Dim nodecollection As NodeCollection = docPage.GetChildNodes(NodeType.Any, True)
For i As Integer = 0 To nodecollection.Count - 1
Dim child As Node = nodecollection(i)
If child.NodeType.Equals(NodeType.Paragraph) Then
ElseIf child.NodeType.Equals(NodeType.Shape) Then
ElseIf child.NodeType.Equals(NodeType.Table) Then
ElseIf child.NodeType.Equals(NodeType.Run) Then
End If
Next i

nodecollection.Count is 72 instead of that how to get only presented elements count, no of Paragraphs count also not coming as in my source document.

Anil kasa

Hi Anil,

Thanks for your inquiry. Please use Document.GetChildNodes method to get the collection of child nodes that match the specified type. To get the collection of Paragraph’s node type, please use Document.GetChildNodes(NodeType.Paragraph, True). Your document contains 22 paragraphs. This method returns the correct value.

Could you please share some more detail about your query what exact you want to achieve using Aspose.Words? We will then provide you more information about your query.