Aspose::Words::Markup::SmartTag Class Reference

Detailed Description

This element specifies the presence of a smart tag around one or more inline structures (runs, images, fields,etc.) within a paragraph.

Smart tags is a kind of custom XML markup. Smart tags provide a facility for embedding customer-defined semantics into the document via the ability to provide a basic namespace/name for a run or set of runs within a document.

SmartTag can be a child of a Paragraph or another SmartTag node.

The complete list of child nodes that can occur inside a smart tag consists of BookmarkStart, BookmarkEnd, FieldStart, FieldSeparator, FieldEnd, FormField, Comment, Footnote, Run, SpecialChar, Shape, GroupShape, CommentRangeStart, CommentRangeEnd, SmartTag.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

#include <Aspose.Words.Cpp/Markup/SmartTag.h>

+ Inheritance diagram for Aspose::Words::Markup::SmartTag:

Public Member Functions

 SmartTag (const SharedPtr< DocumentBase > &doc)
 Initializes a new instance of the SmartTag class. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
String get_Element () const
 Specifies the name of the smart tag within the document. More...
 
NodeType get_NodeType () const override
 Returns NodeType.SmartTag. More...
 
SharedPtr< CustomXmlPropertyCollectionget_Properties () const
 A collection of the smart tag properties. More...
 
String get_Uri () const
 Specifies the namespace URI of the smart tag. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Element (const String &value)
 Setter for get_Element. More...
 
void set_Uri (const String &value)
 Setter for get_Uri. More...
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (const SharedPtr< Node > &newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
bool get_IsComposite () override
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
String GetText () override
 Gets the text of this node and of all its children. More...
 
int32_t IndexOf (const SharedPtr< Node > &child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (const SharedPtr< Node > &newChild)
 Adds the specified node to the beginning of the list of child nodes for this node. More...
 
void RemoveAllChildren ()
 Removes all the child nodes of the current node. More...
 
SharedPtr< NodeRemoveChild (const SharedPtr< Node > &oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (const String &xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (const String &xpath)
 Selects the first Node that matches the XPath expression. More...
 
void SetTemplateWeakPtr (uint32_t argument) 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...
 
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 (const SharedPtr< Node > &rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (const 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 (const 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 CompositeNode
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

◆ SmartTag()

Aspose::Words::Markup::SmartTag::SmartTag ( const System::SharedPtr< Aspose::Words::DocumentBase > &  doc)

Initializes a new instance of the SmartTag class.

When you create a new node, you need to specify a document to which the node belongs. A node cannot exist without a document because it depends on the document-wide structures such as lists and styles. Although a node always belongs to a document, a node might or might not be a part of the document tree.

When a node is created, it belongs to a document, but is not yet part of the document tree and ParentNode is null. To insert a node into the document, use the InsertAfter() or InsertBefore() methods on the parent node.

Parameters
docThe owner document.
Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

Member Function Documentation

◆ Accept()

bool Aspose::Words::Markup::SmartTag::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 create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

Implements Aspose::Words::Node.

◆ get_Element()

System::String Aspose::Words::Markup::SmartTag::get_Element ( ) const

Specifies the name of the smart tag within the document.

Cannot be null.

Default is empty string.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Markup::SmartTag::get_NodeType ( ) const
overridevirtual

Returns NodeType.SmartTag.

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.

◆ get_Properties()

System::SharedPtr<Aspose::Words::Markup::CustomXmlPropertyCollection> Aspose::Words::Markup::SmartTag::get_Properties ( ) const

A collection of the smart tag properties.

Cannot be null.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ get_Uri()

System::String Aspose::Words::Markup::SmartTag::get_Uri ( ) const

Specifies the namespace URI of the smart tag.

Cannot be null.

Default is empty string.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ GetType()

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

Reimplemented from Aspose::Words::CompositeNode.

◆ Is()

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

Reimplemented from Aspose::Words::CompositeNode.

◆ set_Element()

void Aspose::Words::Markup::SmartTag::set_Element ( const System::String value)

◆ set_Uri()

void Aspose::Words::Markup::SmartTag::set_Uri ( const System::String value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Markup::SmartTag::Type ( )
static