node_type property

Body.node_type property

Returns NodeType.BODY.

@property
def node_type(self) -> aspose.words.NodeType:
    ...

Examples

Shows how to iterate through the children of a composite node.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.write("Section 1")
builder.move_to_header_footer(aw.HeaderFooterType.HEADER_PRIMARY)
builder.write("Primary header")
builder.move_to_header_footer(aw.HeaderFooterType.FOOTER_PRIMARY)
builder.write("Primary footer")

section = doc.first_section

# A Section is a composite node and can contain child nodes,
# but only if those child nodes are of a "BODY" or "HEADER_FOOTER" node type.
for node in section:
    if node.node_type == aw.NodeType.BODY:
        body = node.as_body()
        print("Body:")
        print(f"\t\"{body.get_text().strip()}\"")
    elif node.node_type == aw.NodeType.HEADER_FOOTER:
        header_footer = node.as_header_footer()
        print(f"HeaderFooter type: {header_footer.header_footer_type}:")
        print(f"\t\"{header_footer.get_text().strip()}\"")
    else:
        raise Exception("Unexpected node type in a section.")

See Also