CompositeNode — Aspose.Note FOSS for Python API Reference
คลาส: CompositeNode
Properties: aspose.note Properties: from aspose.note import CompositeNode Properties: Node
CompositeNode extends Node ด้วยความสามารถในการเป็นเจ้าของโหนดลูก ทั้งประเภทโหนดเชิงโครงสร้างในโมเดลเอกสาร (Document, Page, Outline, OutlineElement, RichText, Image, Table, TableRow, TableCell, AttachedFile) สืบทอดจาก CompositeNode. คุณไม่ควร instantiate CompositeNode โดยตรง.
Properties
สืบทอดจาก Node
| Properties | Properties | Properties | Properties |
|---|---|---|---|
ParentNode | `Node | None` | Properties |
Document | `Document | None` | Properties |
คุณสมบัติการเข้าถึงโหนดลูก
| Properties | Properties | Properties | Properties |
|---|---|---|---|
FirstChild | `Node | None` | Properties |
LastChild | `Node | None` | Properties |
Properties
AppendChildLast(node)
composite.AppendChildLast(node: Node) -> NodeProperties node เป็นโหนดลูกโดยตรงคนสุดท้าย. ตั้งค่า node.ParentNode = self. คืนค่า node.
AppendChildFirst(node)
composite.AppendChildFirst(node: Node) -> NodeProperties node เป็นโหนดลูกโดยตรงคนแรก. คืนค่า node.
InsertChild(index, node)
composite.InsertChild(index: int, node: Node) -> NodeProperties node ที่ตำแหน่ง index ในรายการโหนดลูก. คืนค่า node.
RemoveChild(node)
composite.RemoveChild(node: Node) -> NoneProperties node จากรายการลูกและชุด node.ParentNode = None.
GetChildNodes(node_type)
composite.GetChildNodes(node_type: type) -> listค้นหาแบบเรียกซ้ำทั่วทั้งต้นไม้ย่อย (depth-first, รวมถึง self) และคืนค่าโหนดทั้งหมดที่ตรงกับ node_type. นี่เป็นวิธีหลักในการรวบรวมอินสแตนซ์ทั้งหมดของคลาสที่กำหนดภายในต้นไม้ย่อยใด ๆ.
Properties
for child in composite:
...การวนซ้ำของ CompositeNode ให้ผลลัพธ์ของ ลูกโดยตรงเท่านั้น. ใช้ GetChildNodes() สำหรับการค้นหาเชิงลึก.
ตัวอย่างการใช้งาน
การเดินทางผ่านโหนดลูกโดยตรงเทียบกับการค้นหาแบบลึก
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 เมื่อโหนดไม่มีลูก. ควรตรวจสอบเสมอก่อนเข้าถึงค่า.
ดูเพิ่มเติม
- Properties: คลาสฐานสำหรับโหนดเอกสารทั้งหมด
- Properties: ราก
CompositeNode - Properties: ระดับหน้า
CompositeNode - RichText: บล็อกข้อความ
CompositeNode - คู่มือผู้พัฒนา