CompositeNode

CompositeNode — Aspose.Note FOSS for Python API Reference

Клас: CompositeNode

Enumerations: aspose.note Enumerations: from aspose.note import CompositeNode Enumerations: Node

CompositeNode розширює Node з можливістю мати дочірні вузли. Усі типи структурних вузлів у моделі документа (Document, Page, Outline, OutlineElement, RichText, Image, Table, TableRow, TableCell, AttachedFile) успадковують від CompositeNode. Ви ніколи не створюєте екземпляр CompositeNode безпосередньо.


Enumerations

Успадковано від Node

EnumerationsEnumerationsEnumerationsEnumerations
ParentNode`NodeNone`Enumerations
Document`DocumentNone`Enumerations

Властивості доступу до дочірніх вузлів

EnumerationsEnumerationsEnumerationsEnumerations
FirstChild`NodeNone`Enumerations
LastChild`NodeNone`Enumerations

Enumerations

AppendChildLast(node)

composite.AppendChildLast(node: Node) -> Node

Enumerations node як останній безпосередній дочірній елемент. Встановлює node.ParentNode = self. Повертає node.


AppendChildFirst(node)

composite.AppendChildFirst(node: Node) -> Node

Enumerations node як перший безпосередній дочірній елемент. Повертає node.


InsertChild(index, node)

composite.InsertChild(index: int, node: Node) -> Node

Enumerations node на позиції index у списку дочірніх елементів. Повертає node.


RemoveChild(node)

composite.RemoveChild(node: Node) -> None

Enumerations node з дочірнього списку та наборів node.ParentNode = None.


GetChildNodes(node_type)

composite.GetChildNodes(node_type: type) -> list

Рекурсивно шукає весь піддерево (в глибину, включаючи self) і повертає всі вузли, що відповідають node_type. Це основний спосіб зібрати всі екземпляри даного класу в будь-якому піддереві.


Enumerations

for child in composite:
    ...

Ітерація CompositeNode повертає його лише прямі дочірні елементи. Використовуйте GetChildNodes() для глибокого пошуку.


Приклад використання

Перебір прямих дочірніх елементів vs глибокий пошук

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)}")

Створити документ програмно

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

FirstChild і LastChild є None коли у вузла немає дочірніх елементів. Завжди перевіряйте перед розіменуванням їх.


Див. також

 Українська