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
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
ParentNode | `Node | None` | Enumerations |
Document | `Document | None` | Enumerations |
Властивості доступу до дочірніх вузлів
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
FirstChild | `Node | None` | Enumerations |
LastChild | `Node | None` | Enumerations |
Enumerations
AppendChildLast(node)
composite.AppendChildLast(node: Node) -> NodeEnumerations node як останній безпосередній дочірній елемент. Встановлює node.ParentNode = self. Повертає node.
AppendChildFirst(node)
composite.AppendChildFirst(node: Node) -> NodeEnumerations node як перший безпосередній дочірній елемент. Повертає node.
InsertChild(index, node)
composite.InsertChild(index: int, node: Node) -> NodeEnumerations node на позиції index у списку дочірніх елементів. Повертає node.
RemoveChild(node)
composite.RemoveChild(node: Node) -> NoneEnumerations 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 коли у вузла немає дочірніх елементів. Завжди перевіряйте перед розіменуванням їх.
Див. також
- Enumerations: базовий клас для всіх вузлів документа
- Enumerations: корінь
CompositeNode - Enumerations: рівень сторінки
CompositeNode - RichText: текстовий блок
CompositeNode - Посібник розробника