Aspose::Words::BuildingBlocks::GlossaryDocument class

GlossaryDocument class

Represents the root element for a glossary document within a Word document. A glossary document is a storage for AutoText, AutoCorrect entries and Building Blocks. To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.

class GlossaryDocument : public Aspose::Words::DocumentBase


Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor.
AppendChild(const System::SharedPtr<Aspose::Words::Node>&)Adds the specified node to the end of the list of child nodes for this node.
Clone(bool)Creates a duplicate of the node.
get_BackgroundShape() constGets or sets the background shape of the document. Can be null.
get_BuildingBlocks()Returns a typed collection that represents all building blocks in the glossary document.
get_ChildNodes()Gets all immediate child nodes of this node.
get_Count()Gets the number of immediate children of this node.
get_CustomNodeId() constSpecifies custom node identifier.
get_Document() const overrideGets this instance.
get_FirstBuildingBlock()Gets the first building block in the glossary document.
get_FirstChild() constGets the first child of the node.
get_FontInfos() constProvides access to properties of fonts used in this document.
get_HasChildNodes()Returns true if this node has any child nodes.
get_IsComposite() overrideReturns true as this node can have child nodes.
get_LastBuildingBlock()Gets the last building block in the glossary document.
get_LastChild() constGets the last child of the node.
get_Lists() constProvides access to the list formatting used in the document.
get_NextSibling()Gets the node immediately following this node.
get_NodeChangingCallback()Called when a node is inserted or removed in the document.
get_NodeType() const overrideReturns the GlossaryDocument value.
get_PageColor()Gets or sets the page color of the document. This property is a simpler version of BackgroundShape.
get_ParentNode()Gets the immediate parent of this node.
get_PreviousSibling()Gets the node immediately preceding this node.
get_Range()Returns a Range object that represents the portion of a document that is contained in this node.
get_ResourceLoadingCallback() constAllows to control how external resources are loaded.
get_Styles() constReturns a collection of styles defined in the document.
get_WarningCallback() constCalled during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss.
GetAncestor(Aspose::Words::NodeType)Gets the first ancestor of the specified NodeType.
GetBuildingBlock(Aspose::Words::BuildingBlocks::BuildingBlockGallery, const System::String&, const System::String&)Finds a building block using the specified gallery, category and name.
GetChild(Aspose::Words::NodeType, int32_t, bool)Returns an Nth child node that matches the specified type.
GetChildNodes(Aspose::Words::NodeType, bool)Returns a live collection of child nodes that match the specified type.
GetEnumerator() overrideProvides support for the for each style iteration over the child nodes of this node.
GetText() overrideGets the text of this node and of all its children.
GetType() const override
ImportNode(const System::SharedPtr<Aspose::Words::Node>&, bool)Imports a node from another document to the current document.
ImportNode(const System::SharedPtr<Aspose::Words::Node>&, bool, Aspose::Words::ImportFormatMode)Imports a node from another document to the current document with an option to control formatting.
IndexOf(const System::SharedPtr<Aspose::Words::Node>&)Returns the index of the specified child node in the child node array.
InsertAfter(const System::SharedPtr<Aspose::Words::Node>&, const System::SharedPtr<Aspose::Words::Node>&)Inserts the specified node immediately after the specified reference node.
InsertBefore(const System::SharedPtr<Aspose::Words::Node>&, const System::SharedPtr<Aspose::Words::Node>&)Inserts the specified node immediately before the specified reference node.
Is(const System::TypeInfo&) const override
NextPreOrder(const System::SharedPtr<Aspose::Words::Node>&)Gets next node according to the pre-order tree traversal algorithm.
static NodeTypeToString(Aspose::Words::NodeType)A utility method that converts a node type enum value into a user friendly string.
PrependChild(const System::SharedPtr<Aspose::Words::Node>&)Adds the specified node to the beginning of the list of child nodes for this node.
PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node>&)Gets the previous node according to the pre-order tree traversal algorithm.
Remove()Removes itself from the parent.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveChild(const System::SharedPtr<Aspose::Words::Node>&)Removes the specified child node.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
SelectNodes(const System::String&)Selects a list of nodes matching the XPath expression.
SelectSingleNode(const System::String&)Selects the first Node that matches the XPath expression.
set_BackgroundShape(const System::SharedPtr<Aspose::Words::Drawing::Shape>&)Setter for Aspose::Words::DocumentBase::get_BackgroundShape.
set_CustomNodeId(int32_t)Setter for Aspose::Words::Node::get_CustomNodeId.
set_NodeChangingCallback(const System::SharedPtr<Aspose::Words::INodeChangingCallback>&)Setter for Aspose::Words::DocumentBase::get_NodeChangingCallback.
set_PageColor(System::Drawing::Color)Setter for Aspose::Words::DocumentBase::get_PageColor.
set_ResourceLoadingCallback(const System::SharedPtr<Aspose::Words::Loading::IResourceLoadingCallback>&)Setter for Aspose::Words::DocumentBase::get_ResourceLoadingCallback.
set_WarningCallback(const System::SharedPtr<Aspose::Words::IWarningCallback>&)Setter for Aspose::Words::DocumentBase::get_WarningCallback.
SetTemplateWeakPtr(uint32_t) override
ToString(Aspose::Words::SaveFormat)Exports the content of the node into a string in the specified format.
ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&)Exports the content of the node into a string using the specified save options.
static Type()


Some documents, usually templates, can contain AutoText, AutoCorrect entries and/or Building Blocks (also known as glossary document entries, document parts or building blocks).

To access building blocks, you need to load a document into a Document object. Building blocks will be available via the GlossaryDocument property.

GlossaryDocument can contain any number of BuildingBlock objects. Each BuildingBlock represents one document part.

Corresponds to the glossaryDocument and docParts elements in OOXML.


Shows ways of accessing building blocks in a glossary document.

void GlossaryDocument_()
    auto doc = MakeObject<Document>();
    auto glossaryDoc = MakeObject<GlossaryDocument>();

    for (int i = 1; i <= 5; ++i)
        auto block = MakeObject<BuildingBlock>(glossaryDoc);
        block->set_Name(String(u"Block ") + System::Convert::ToString(i));
    ASSERT_EQ(5, glossaryDoc->get_BuildingBlocks()->get_Count());


    // There are various ways of accessing building blocks.
    // 1 -  Get the first/last building blocks in the collection:
    ASSERT_EQ(u"Block 1", glossaryDoc->get_FirstBuildingBlock()->get_Name());
    ASSERT_EQ(u"Block 5", glossaryDoc->get_LastBuildingBlock()->get_Name());

    // 2 -  Get a building block by index:
    ASSERT_EQ(u"Block 2", glossaryDoc->get_BuildingBlocks()->idx_get(1)->get_Name());
    ASSERT_EQ(u"Block 3", glossaryDoc->get_BuildingBlocks()->ToArray()->idx_get(2)->get_Name());

    // 3 -  Get the first building block that matches a gallery, name and category:
    ASSERT_EQ(u"Block 4", glossaryDoc->GetBuildingBlock(BuildingBlockGallery::All, u"(Empty Category)", u"Block 4")->get_Name());

    // We will do that using a custom visitor,
    // which will give every BuildingBlock in the GlossaryDocument a unique GUID
    auto visitor = MakeObject<ExBuildingBlocks::GlossaryDocVisitor>();

    std::cout << visitor->GetText() << std::endl;

    // In Microsoft Word, we can access the building blocks via "Insert" -> "Quick Parts" -> "Building Blocks Organizer".
    doc->Save(ArtifactsDir + u"BuildingBlocks.GlossaryDocument.dotx");

class GlossaryDocVisitor : public DocumentVisitor
        mBlocksByGuid = MakeObject<System::Collections::Generic::Dictionary<System::Guid, SharedPtr<BuildingBlock>>>();
        mBuilder = MakeObject<System::Text::StringBuilder>();

    String GetText()
        return mBuilder->ToString();

    SharedPtr<System::Collections::Generic::Dictionary<System::Guid, SharedPtr<BuildingBlock>>> GetDictionary()
        return mBlocksByGuid;

    VisitorAction VisitGlossaryDocumentStart(SharedPtr<GlossaryDocument> glossary) override
        mBuilder->AppendLine(u"Glossary document found!");
        return VisitorAction::Continue;

    VisitorAction VisitGlossaryDocumentEnd(SharedPtr<GlossaryDocument> glossary) override
        mBuilder->AppendLine(u"Reached end of glossary!");
        mBuilder->AppendLine(String(u"BuildingBlocks found: ") + mBlocksByGuid->get_Count());
        return VisitorAction::Continue;

    VisitorAction VisitBuildingBlockStart(SharedPtr<BuildingBlock> block) override
        mBlocksByGuid->Add(block->get_Guid(), block);
        return VisitorAction::Continue;

    VisitorAction VisitBuildingBlockEnd(SharedPtr<BuildingBlock> block) override
        mBuilder->AppendLine(String(u"\tVisited block \"") + block->get_Name() + u"\"");
        mBuilder->AppendLine(String(u"\t Type: ") + System::ObjectExt::ToString(block->get_Type()));
        mBuilder->AppendLine(String(u"\t Gallery: ") + System::ObjectExt::ToString(block->get_Gallery()));
        mBuilder->AppendLine(String(u"\t Behavior: ") + System::ObjectExt::ToString(block->get_Behavior()));
        mBuilder->AppendLine(String(u"\t Description: ") + block->get_Description());

        return VisitorAction::Continue;

    SharedPtr<System::Collections::Generic::Dictionary<System::Guid, SharedPtr<BuildingBlock>>> mBlocksByGuid;
    SharedPtr<System::Text::StringBuilder> mBuilder;

See Also