NodeNodeType Property
Gets the type of this node.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
public abstract NodeType NodeType { get; }

Property Value

Type: NodeType
Shows how to enumerate immediate child nodes of a composite node using NextSibling. In this example we enumerate all paragraphs of a section body.

// Get the section that we want to work on.
Section section = doc.Sections[0];
Body body = section.Body;

// Loop starting from the first child until we reach null.
for (Node node = body.FirstChild; node != null; node = node.NextSibling)
    // Output the types of the nodes that we come across.
Shows how to remove all nodes of a specific type from a composite node. In this example we remove tables from a section body.

// Get the section that we want to work on.
Section section = doc.Sections[0];
Body body = section.Body;

// Select the first child node in the body.
Node curNode = body.FirstChild;

while (curNode != null)
    // Save the pointer to the next sibling node because if the current 
    // node is removed from the parent in the next step, we will have 
    // no way of finding the next node to continue the loop.
    Node nextNode = curNode.NextSibling;

    // A section body can contain Paragraph and Table nodes.
    // If the node is a Table, remove it from the parent.
    if (curNode.NodeType.Equals(NodeType.Table))

    // Continue going through child nodes until null (no more siblings) is reached.
    curNode = nextNode;
Shows how to retrieve the NodeType enumeration of nodes.

Document doc = new Document(MyDir + "Document.doc");

// Let's pick a node that we can't be quite sure of what type it is.
// In this case lets pick the first node of the first paragraph in the body of the document
Node node = doc.FirstSection.Body.FirstParagraph.FirstChild;
Console.WriteLine("NodeType of first child: " + Node.NodeTypeToString(node.NodeType));

// This time let's pick a node that we know the type of. Create a new paragraph and a table node.
Paragraph para = new Paragraph(doc);
Table table = new Table(doc);

// Access to NodeType for typed nodes will always return their specific NodeType. 
// i.e A paragraph node will always return NodeType.Paragraph, a table node will always return NodeType.Table.
Console.WriteLine("NodeType of Paragraph: " + Node.NodeTypeToString(para.NodeType));
Console.WriteLine("NodeType of Table: " + Node.NodeTypeToString(table.NodeType));
See Also