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
Methods
Method | Description |
---|---|
Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor. |
AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the end of the Glossary document. |
AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the start of the Glossary document. |
AppendChild(T) | |
Clone(bool) | Creates a duplicate of the node. |
get_BackgroundShape() const | Gets 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_Count() | Gets the number of immediate children of this node. |
get_CustomNodeId() const | Specifies custom node identifier. |
get_Document() const override | Gets this instance. |
get_FirstBuildingBlock() | Gets the first building block in the glossary document. |
get_FirstChild() const | Gets the first child of the node. |
get_FontInfos() const | Provides access to properties of fonts used in this document. |
get_FootnoteSeparators() const | Provides access to the footnote/endnote separators defined in the document. |
get_HasChildNodes() | Returns true if this node has any child nodes. |
get_IsComposite() override | Returns true as this node can have child nodes. |
get_LastBuildingBlock() | Gets the last building block in the glossary document. |
get_LastChild() const | Gets the last child of the node. |
get_Lists() const | Provides access to the list formatting used in the document. |
get_NextNode() const | |
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 override | Returns 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_PrevNode() const | |
get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. |
get_ResourceLoadingCallback() const | Allows to control how external resources are loaded. |
get_Styles() const | Returns a collection of styles defined in the document. |
get_WarningCallback() const | Called 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. |
GetAncestorOf() | |
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() override | Provides support for the for each style iteration over the child nodes of this node. |
GetText() override | Gets 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(T, const System::SharedPtr<Aspose::Words::Node>&) | |
InsertBefore(T, const System::SharedPtr<Aspose::Words::Node>&) | |
Is(const System::TypeInfo&) const override | |
IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&) | |
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(T) | |
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(T) | |
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_NextNode(const System::SharedPtr<Aspose::Words::Node>&) | |
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_PrevNode(const System::SharedPtr<Aspose::Words::Node>&) | |
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. |
SetParent(const System::SharedPtr<Aspose::Words::Node>&) | |
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() |
Remarks
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.
Examples
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));
glossaryDoc->AppendChild(block);
}
ASSERT_EQ(5, glossaryDoc->get_BuildingBlocks()->get_Count());
doc->set_GlossaryDocument(glossaryDoc);
// 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>();
glossaryDoc->Accept(visitor);
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
{
public:
GlossaryDocVisitor()
{
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
{
block->set_Guid(System::Guid::NewGuid());
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;
}
private:
SharedPtr<System::Collections::Generic::Dictionary<System::Guid, SharedPtr<BuildingBlock>>> mBlocksByGuid;
SharedPtr<System::Text::StringBuilder> mBuilder;
};
See Also
- Class DocumentBase
- Namespace Aspose::Words::BuildingBlocks
- Library Aspose.Words for C++