SmartTagAccept Method

Accepts a visitor.

Namespace:  Aspose.Words.Markup
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public override bool Accept(
	DocumentVisitor visitor
)

Parameters

visitor
Type: Aspose.WordsDocumentVisitor
The visitor that will visit the nodes.

Return Value

Type: Boolean
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.
Remarks

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.

Remarks
Calls VisitSmartTagStart(SmartTag), then calls Accept(DocumentVisitor) for all child nodes of the smart tag and calls VisitSmartTagEnd(SmartTag) at the end.
Examples
Shows how to create smart tags.
public void SmartTags()
{
    Document doc = new Document();
    SmartTag smartTag = new SmartTag(doc);
    smartTag.Element = "date";

    // Specify a date and set smart tag properties accordingly
    smartTag.AppendChild(new Run(doc, "May 29, 2019"));

    smartTag.Properties.Add(new CustomXmlProperty("Day", "", "29"));
    smartTag.Properties.Add(new CustomXmlProperty("Month", "", "5"));
    smartTag.Properties.Add(new CustomXmlProperty("Year", "", "2019"));

    // Set the smart tag's uri to the default
    smartTag.Uri = "urn:schemas-microsoft-com:office:smarttags";

    doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
    doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a date. "));

    // Create and add one more smart tag, this time for a financial symbol
    smartTag = new SmartTag(doc);
    smartTag.Element = "stockticker";
    smartTag.Uri = "urn:schemas-microsoft-com:office:smarttags";

    smartTag.AppendChild(new Run(doc, "MSFT"));

    doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
    doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a stock ticker."));

    // Print all the smart tags in our document with a document visitor
    doc.Accept(new SmartTagVisitor());

    doc.Save(ArtifactsDir + "StructuredDocumentTag.SmartTags.docx");
}

/// <summary>
/// DocumentVisitor implementation that prints smart tags and their contents
/// </summary>
private class SmartTagVisitor : DocumentVisitor
{
    /// <summary>
    /// Called when a SmartTag node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitSmartTagStart(SmartTag smartTag)
    {
        Console.WriteLine($"Smart tag type: {smartTag.Element}");
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when the visiting of a SmartTag node is ended.
    /// </summary>
    public override VisitorAction VisitSmartTagEnd(SmartTag smartTag)
    {
        Console.WriteLine($"\tContents: \"{smartTag.ToString(SaveFormat.Text)}\"");

        if (smartTag.Properties.Count == 0)
        {
            Console.WriteLine("\tContains no properties");
        }
        else
        {
            Console.Write("\tProperties: ");
            string[] properties = new string[smartTag.Properties.Count];
            int index = 0;         

            foreach (CustomXmlProperty cxp in smartTag.Properties)
                properties[index++] = $"\"{cxp.Name}\" = \"{cxp.Value}\"";

            Console.WriteLine(string.Join(", ", properties));
        }

        return VisitorAction.Continue;
    }
}
See Also