search/mag_sel search/close
Aspose::Words::SubDocument Class Reference

Represents a SubDocument - which is a reference to an externally stored document.

In this version of Aspose.Words, SubDocument nodes do not provide public methods and properties to create or modify a subdocument. In this version you are not able to instantiate SubDocument nodes or modify existing except deleting them.

SubDocument can only be a child of Paragraph.

Examples

Shows how to access a master document's subdocument.

auto doc = MakeObject<Document>(MyDir + u"Master document.docx");
SharedPtr<NodeCollection> subDocuments = doc->GetChildNodes(NodeType::SubDocument, true);
// This node serves as a reference to an external document, and its contents cannot be accessed.
auto subDocument = System::DynamicCast<SubDocument>(subDocuments->idx_get(0));
ASSERT_FALSE(subDocument->get_IsComposite());

#include <Aspose.Words.Cpp/SubDocument.h>

+ Inheritance diagram for Aspose::Words::SubDocument:

Public Member Functions

bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
NodeType get_NodeType () const override
 Returns NodeType.SubDocument More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 Creates a duplicate of the node. More...
 
int32_t get_CustomNodeId () const
 Specifies custom node identifier. More...
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
virtual bool get_IsComposite ()
 Returns true if this node can contain other nodes. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
virtual String GetText ()
 Gets the text of this node and of all its children. More...
 
SharedPtr< NodeNextPreOrder (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
void set_CustomNodeId (int32_t value)
 Setter for get_CustomNodeId. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 

Member Function Documentation

◆ Accept()

bool Aspose::Words::SubDocument::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the nodes.
Returns
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.
Examples

Shows how to use a document visitor to print a document's node structure.

void DocStructureToText()
{
auto doc = MakeObject<Document>(MyDir + u"DocumentVisitor-compatible features.docx");
auto visitor = MakeObject<ExDocumentVisitor::DocStructurePrinter>();
// When we get a composite node to accept a document visitor, the visitor visits the accepting node,
// and then traverses all the node's children in a depth-first manner.
// The visitor can read and modify each visited node.
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class DocStructurePrinter : public DocumentVisitor
{
public:
DocStructurePrinter() : mDocTraversalDepth(0)
{
mAcceptingNodeChildTree = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return mAcceptingNodeChildTree->ToString();
}
VisitorAction VisitDocumentStart(SharedPtr<Document> doc) override
{
int childNodeCount = doc->GetChildNodes(NodeType::Any, true)->get_Count();
IndentAndAppendLine(String(u"[Document start] Child nodes: ") + childNodeCount);
mDocTraversalDepth++;
// Allow the visitor to continue visiting other nodes.
}
VisitorAction VisitDocumentEnd(SharedPtr<Document> doc) override
{
mDocTraversalDepth--;
IndentAndAppendLine(u"[Document end]");
}
VisitorAction VisitSectionStart(SharedPtr<Section> section) override
{
// Get the index of our section within the document.
SharedPtr<NodeCollection> docSections = section->get_Document()->GetChildNodes(NodeType::Section, false);
int sectionIndex = docSections->IndexOf(section);
IndentAndAppendLine(String(u"[Section start] Section index: ") + sectionIndex);
mDocTraversalDepth++;
}
VisitorAction VisitSectionEnd(SharedPtr<Section> section) override
{
mDocTraversalDepth--;
IndentAndAppendLine(u"[Section end]");
}
VisitorAction VisitBodyStart(SharedPtr<Body> body) override
{
int paragraphCount = body->get_Paragraphs()->get_Count();
IndentAndAppendLine(String(u"[Body start] Paragraphs: ") + paragraphCount);
mDocTraversalDepth++;
}
VisitorAction VisitBodyEnd(SharedPtr<Body> body) override
{
mDocTraversalDepth--;
IndentAndAppendLine(u"[Body end]");
}
VisitorAction VisitParagraphStart(SharedPtr<Paragraph> paragraph) override
{
IndentAndAppendLine(u"[Paragraph start]");
mDocTraversalDepth++;
}
VisitorAction VisitParagraphEnd(SharedPtr<Paragraph> paragraph) override
{
mDocTraversalDepth--;
IndentAndAppendLine(u"[Paragraph end]");
}
VisitorAction VisitRun(SharedPtr<Run> run) override
{
IndentAndAppendLine(String(u"[Run] \"") + run->GetText() + u"\"");
}
VisitorAction VisitSubDocument(SharedPtr<SubDocument> subDocument) override
{
IndentAndAppendLine(u"[SubDocument]");
}
private:
int mDocTraversalDepth;
SharedPtr<System::Text::StringBuilder> mAcceptingNodeChildTree;
void IndentAndAppendLine(String text)
{
for (int i = 0; i < mDocTraversalDepth; i++)
{
mAcceptingNodeChildTree->Append(u"| ");
}
mAcceptingNodeChildTree->AppendLine(text);
}
};

Implements Aspose::Words::Node.

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::SubDocument::get_NodeType ( ) const
overridevirtual

Returns NodeType.SubDocument

Examples

Shows how to access a master document's subdocument.

auto doc = MakeObject<Document>(MyDir + u"Master document.docx");
SharedPtr<NodeCollection> subDocuments = doc->GetChildNodes(NodeType::SubDocument, true);
// This node serves as a reference to an external document, and its contents cannot be accessed.
auto subDocument = System::DynamicCast<SubDocument>(subDocuments->idx_get(0));
ASSERT_FALSE(subDocument->get_IsComposite());

Implements Aspose::Words::Node.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::SubDocument::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::Node.

◆ Is()

virtual bool Aspose::Words::SubDocument::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::Node.

◆ Type()

static const System::TypeInfo& Aspose::Words::SubDocument::Type ( )
static