CompositeNode

CompositeNode — Aspose.Note FOSS for Python API Reference

Lớp: CompositeNode

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

CompositeNode mở rộng Node với khả năng sở hữu các nút con. Tất cả các loại nút cấu trúc trong mô hình tài liệu (Document, Page, Outline, OutlineElement, RichText, Image, Table, TableRow, TableCell, AttachedFile) kế thừa từ CompositeNode. Bạn không bao giờ khởi tạo CompositeNode trực tiếp.


Enumerations

Kế thừa từ Node

EnumerationsEnumerationsEnumerationsEnumerations
ParentNode`NodeNone`Enumerations
Document`DocumentNone`Enumerations

Thuộc tính truy cập nút con

EnumerationsEnumerationsEnumerationsEnumerations
FirstChild`NodeNone`Enumerations
LastChild`NodeNone`Enumerations

Enumerations

AppendChildLast(node)

composite.AppendChildLast(node: Node) -> Node

Enumerations node như là nút con trực tiếp cuối cùng. Đặt node.ParentNode = self. Trả về node.


AppendChildFirst(node)

composite.AppendChildFirst(node: Node) -> Node

Enumerations node như là nút con trực tiếp đầu tiên. Trả về node.


InsertChild(index, node)

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

Enumerations node tại vị trí index trong danh sách con. Trả về node.


RemoveChild(node)

composite.RemoveChild(node: Node) -> None

Enumerations node từ danh sách con và đặt node.ParentNode = None.


GetChildNodes(node_type)

composite.GetChildNodes(node_type: type) -> list

Tìm kiếm đệ quy toàn bộ cây con (theo chiều sâu, bao gồm self) và trả về tất cả các nút khớp với node_type. Đây là cách chính để thu thập tất cả các thể hiện của một lớp nhất định trong bất kỳ cây con nào.


Enumerations

for child in composite:
    ...

Lặp qua một CompositeNode trả về các con trực tiếp duy nhất. Sử dụng GetChildNodes() để tìm kiếm sâu.


Ví dụ sử dụng

Duyệt các nút con trực tiếp so với tìm kiếm sâu

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

Xây dựng tài liệu bằng chương trình

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

FirstChildLastChildNone khi nút không có con. Luôn kiểm tra trước khi tham chiếu tới chúng.


Xem Thêm

 Tiếng Việt