SmartTagUri Property |
Namespace: Aspose.Words.Markup
Cannot be null.
Default is empty string.
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; } }