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

Represents a start of a bookmark in a Word document.

A complete bookmark in a Word document consists of a BookmarkStart and a matching BookmarkEnd with the same bookmark name.

BookmarkStart and BookmarkEnd are just markers inside a document that specify where the bookmark starts and ends.

Use the Bookmark class as a "facade" to work with a bookmark as a single object.

Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

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

+ Inheritance diagram for Aspose::Words::BookmarkStart:

Public Member Functions

 BookmarkStart (SharedPtr< DocumentBase > doc, String name)
 Initializes a new instance of the BookmarkStart class. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
SharedPtr< Bookmarkget_Bookmark ()
 Gets the facade object that encapsulates this bookmark start and end. More...
 
Aspose::Words::Revisions::DisplacedByType get_DisplacedByCustomXml () override
 
String get_Name () override
 Gets or sets the bookmark name. More...
 
NodeType get_NodeType () const override
 Returns BookmarkStart. More...
 
String GetText () override
 Returns an empty string. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_DisplacedByCustomXml (Aspose::Words::Revisions::DisplacedByType value) override
 
void set_Name (String value) override
 Setter for get_Name. More...
 
- 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 ()
 
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 ()
 

Constructor & Destructor Documentation

◆ BookmarkStart()

Aspose::Words::BookmarkStart::BookmarkStart ( System::SharedPtr< Aspose::Words::DocumentBase doc,
System::String  name 
)

Initializes a new instance of the BookmarkStart class.

Parameters
docThe owner document.
nameThe name of the bookmark. Cannot be null.
Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

Member Function Documentation

◆ Accept()

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

Accepts a visitor.

Calls VisitBookmarkStart().

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the node.
Returns
False if the visitor requested the enumeration to stop.
Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

Implements Aspose::Words::Node.

◆ get_Bookmark()

System::SharedPtr<Aspose::Words::Bookmark> Aspose::Words::BookmarkStart::get_Bookmark ( )

Gets the facade object that encapsulates this bookmark start and end.

Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

◆ get_DisplacedByCustomXml()

Aspose::Words::Revisions::DisplacedByType Aspose::Words::BookmarkStart::get_DisplacedByCustomXml ( )
override

◆ get_Name()

System::String Aspose::Words::BookmarkStart::get_Name ( )
override

Gets or sets the bookmark name.

Cannot be null.

Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

◆ get_NodeType()

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

Returns BookmarkStart.

Examples

Shows how to traverse a composite node's tree of child nodes.

void RecurseChildren()
{
auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
ASSERT_TRUE(doc->get_IsComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
TraverseAllNodes(doc, 0);
}
void TraverseAllNodes(SharedPtr<CompositeNode> parentNode, int depth)
{
for (SharedPtr<Node> childNode = parentNode->get_FirstChild(); childNode != nullptr; childNode = childNode->get_NextSibling())
{
std::cout << (String(u'\t', depth)) << Node::NodeTypeToString(childNode->get_NodeType());
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode->get_IsComposite())
{
std::cout << std::endl;
TraverseAllNodes(System::DynamicCast<CompositeNode>(childNode), depth + 1);
}
else if (System::ObjectExt::Is<Inline>(childNode))
{
std::cout << " - \"" << childNode->GetText().Trim() << "\"" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}

Implements Aspose::Words::Node.

◆ GetText()

System::String Aspose::Words::BookmarkStart::GetText ( )
overridevirtual

Returns an empty string.

Returns
An empty string.
Examples

Shows how to add bookmarks and update their contents.

void CreateUpdateAndPrintBookmarks()
{
// Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
SharedPtr<Document> doc = CreateDocumentWithBookmarks(3);
SharedPtr<BookmarkCollection> bookmarks = doc->get_Range()->get_Bookmarks();
PrintAllBookmarkInfo(bookmarks);
// Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
bookmarks->idx_get(0)->set_Name(String::Format(u"{0}_NewName", bookmarks->idx_get(0)->get_Name()));
bookmarks->idx_get(u"MyBookmark_2")->set_Text(String::Format(u"Updated text contents of {0}", bookmarks->idx_get(1)->get_Name()));
// Print all bookmarks again to see updated values.
PrintAllBookmarkInfo(bookmarks);
}
static SharedPtr<Document> CreateDocumentWithBookmarks(int numberOfBookmarks)
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
for (int i = 1; i <= numberOfBookmarks; i++)
{
String bookmarkName = String(u"MyBookmark_") + i;
builder->Write(u"Text before bookmark.");
builder->StartBookmark(bookmarkName);
builder->Write(String::Format(u"Text inside {0}.", bookmarkName));
builder->EndBookmark(bookmarkName);
builder->Writeln(u"Text after bookmark.");
}
return doc;
}
static void PrintAllBookmarkInfo(SharedPtr<BookmarkCollection> bookmarks)
{
auto bookmarkVisitor = MakeObject<ExBookmarks::BookmarkInfoPrinter>();
// Get each bookmark in the collection to accept a visitor that will print its contents.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Bookmark>>> enumerator = bookmarks->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Bookmark> currentBookmark = enumerator->get_Current();
if (currentBookmark != nullptr)
{
currentBookmark->get_BookmarkStart()->Accept(bookmarkVisitor);
currentBookmark->get_BookmarkEnd()->Accept(bookmarkVisitor);
std::cout << currentBookmark->get_BookmarkStart()->GetText() << std::endl;
}
}
}
}
class BookmarkInfoPrinter : public DocumentVisitor
{
public:
VisitorAction VisitBookmarkStart(SharedPtr<BookmarkStart> bookmarkStart) override
{
std::cout << "BookmarkStart name: \"" << bookmarkStart->get_Name() << "\", Contents: \"" << bookmarkStart->get_Bookmark()->get_Text() << "\""
<< std::endl;
}
VisitorAction VisitBookmarkEnd(SharedPtr<BookmarkEnd> bookmarkEnd) override
{
std::cout << "BookmarkEnd name: \"" << bookmarkEnd->get_Name() << "\"" << std::endl;
}
};

Reimplemented from Aspose::Words::Node.

◆ GetType()

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

Reimplemented from Aspose::Words::Node.

◆ Is()

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

Reimplemented from Aspose::Words::Node.

◆ set_DisplacedByCustomXml()

void Aspose::Words::BookmarkStart::set_DisplacedByCustomXml ( Aspose::Words::Revisions::DisplacedByType  value)
override

◆ set_Name()

void Aspose::Words::BookmarkStart::set_Name ( System::String  value)
override

◆ Type()

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