Aspose::Words::CompositeNode::get_LastChild метод

CompositeNode::get_LastChild method

Возвращает последнего дочернего узла.

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::get_LastChild() const

Примеры

Показывает, как использовать методы Node и CompositeNode для удаления раздела перед последним разделом в документе.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

builder->Writeln(u"Section 1 text.");
builder->InsertBreak(Aspose::Words::BreakType::SectionBreakContinuous);
builder->Writeln(u"Section 2 text.");

// Оба раздела являются соседями друг друга.
auto lastSection = System::ExplicitCast<Aspose::Words::Section>(doc->get_LastChild());
auto firstSection = System::ExplicitCast<Aspose::Words::Section>(lastSection->get_PreviousSibling());

// Удалите раздел, основываясь на его соседних отношениях с другим разделом.
if (lastSection->get_PreviousSibling() != nullptr)
{
    doc->RemoveChild<System::SharedPtr<Aspose::Words::Section>>(firstSection);
}

// Раздел, который мы удалили, был первым, оставив документ только со вторым.
ASSERT_EQ(u"Section 2 text.", doc->GetText().Trim());

См. также