CompositeNode — Aspose.Note FOSS for Python API Reference
Class: CompositeNode
Package: aspose.note
Import: from aspose.note import CompositeNode
Inherits: Node
CompositeNode extends Node with the ability to own child nodes. All structural node types in the document model (Document, Page, Outline, OutlineElement, RichText, Image, Table, TableRow, TableCell, AttachedFile) inherit from CompositeNode. You never instantiate CompositeNode directly.
Properties
Inherited from Node
| Property | Type | Access | Description |
|---|---|---|---|
ParentNode | Node | None | Read | Parent node in the document tree |
Document | Document | None | Read | Root Document ancestor |
NodeType | NodeType | Read | Concrete node type identifier |
Child-access Properties
| Property | Type | Access | Description |
|---|---|---|---|
FirstChild | Node | None | Read | First direct child node, or None if the node has no children |
LastChild | Node | None | Read | Last direct child node, or None if the node has no children |
Methods
AppendChildLast(node)
composite.AppendChildLast(node: Node) -> NodeAdds node as the last direct child. Sets node.ParentNode = self. Returns node.
AppendChildFirst(node)
composite.AppendChildFirst(node: Node) -> NodeAdds node as the first direct child. Returns node.
InsertChild(index, node)
composite.InsertChild(index: int, node: Node) -> NodeInserts node at position index in the child list. Returns node.
RemoveChild(node)
composite.RemoveChild(node: Node) -> NoneRemoves node from the child list and sets node.ParentNode = None.
GetChildNodes(node_type)
composite.GetChildNodes(node_type: type) -> listRecursively searches the entire subtree (depth-first, including self) and returns all nodes matching node_type. This is the primary way to collect all instances of a given class within any subtree.
Iteration
for child in composite:
...Iterating a CompositeNode yields its direct children only. Use GetChildNodes() for a deep search.
Usage Example
Traverse direct children vs deep search
from aspose.note import Document, Page, Outline, RichText
doc = Document("MyNotes.one")
first_page = doc.GetChildNodes(Page)[0]
# Direct children of a page (Outline nodes)
print("Direct children of first page:")
for child in first_page:
print(f" {child.NodeType}")
# Deep search — all RichText nodes anywhere under first_page
all_rt = first_page.GetChildNodes(RichText)
print(f"\nAll RichText nodes in first page: {len(all_rt)}")Build a document programmatically
from aspose.note import Document, Page, Outline, OutlineElement, RichText, SaveFormat, PdfSaveOptions
doc = Document()
page = Page()
outline = Outline()
oe = OutlineElement()
rt = RichText()
rt.Append("Hello, OneNote!")
oe.AppendChildLast(rt)
outline.AppendChildLast(oe)
page.AppendChildLast(outline)
doc.AppendChildLast(page)
doc.Save("output.pdf", PdfSaveOptions(SaveFormat.Pdf))None-Safety
FirstChild and LastChild are None when the node has no children. Always guard before dereferencing them.
See Also
- Node: base class for all document nodes
- Document: root
CompositeNode - Page: page-level
CompositeNode - RichText: text block
CompositeNode - Developer Guide