Aspose::Words::Body::get_NodeType method
Contents
[
Hide
]Body::get_NodeType method
Returns Body.
Aspose::Words::NodeType Aspose::Words::Body::get_NodeType() const override
Examples
Shows how to iterate through the children of a composite node.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->Write(u"Section 1");
builder->MoveToHeaderFooter(Aspose::Words::HeaderFooterType::HeaderPrimary);
builder->Write(u"Primary header");
builder->MoveToHeaderFooter(Aspose::Words::HeaderFooterType::FooterPrimary);
builder->Write(u"Primary footer");
System::SharedPtr<Aspose::Words::Section> section = doc->get_FirstSection();
// A Section is a composite node and can contain child nodes,
// but only if those child nodes are of a "Body" or "HeaderFooter" node type.
for (auto&& node : System::IterateOver(section))
{
switch (node->get_NodeType())
{
case Aspose::Words::NodeType::Body:
{
auto body = System::ExplicitCast<Aspose::Words::Body>(node);
std::cout << "Body:" << std::endl;
std::cout << System::String::Format(u"\t\"{0}\"", body->GetText().Trim()) << std::endl;
break;
}
case Aspose::Words::NodeType::HeaderFooter:
{
auto headerFooter = System::ExplicitCast<Aspose::Words::HeaderFooter>(node);
std::cout << System::String::Format(u"HeaderFooter type: {0}:", headerFooter->get_HeaderFooterType()) << std::endl;
std::cout << System::String::Format(u"\t\"{0}\"", headerFooter->GetText().Trim()) << std::endl;
break;
}
default:
{
throw System::Exception(u"Unexpected node type in a section.");
}
}
}
See Also
- Enum NodeType
- Class Body
- Namespace Aspose::Words
- Library Aspose.Words for C++