SmartTag Class |
Namespace: Aspose.Words.Markup
The SmartTag type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | SmartTag |
Initializes a new instance of the SmartTag class.
|
Name | Description | |
---|---|---|
![]() ![]() | ChildNodes |
Gets all immediate child nodes of this node.
(Inherited from CompositeNode.) |
![]() ![]() | Count |
Gets the number of immediate children of this node.
(Inherited from CompositeNode.) |
![]() ![]() | Document |
Gets the document to which this node belongs.
(Inherited from Node.) |
![]() ![]() | Element |
Specifies the name of the smart tag within the document.
|
![]() ![]() | FirstChild |
Gets the first child of the node.
(Inherited from CompositeNode.) |
![]() ![]() | HasChildNodes |
Returns true if this node has any child nodes.
(Inherited from CompositeNode.) |
![]() ![]() | IsComposite |
Returns true as this node can have child nodes.
(Inherited from CompositeNode.) |
![]() ![]() | LastChild |
Gets the last child of the node.
(Inherited from CompositeNode.) |
![]() ![]() | NextSibling |
Gets the node immediately following this node.
(Inherited from Node.) |
![]() ![]() | NodeType |
Returns NodeType.SmartTag.
(Overrides NodeNodeType.) |
![]() ![]() | ParentNode |
Gets the immediate parent of this node.
(Inherited from Node.) |
![]() ![]() | PreviousSibling |
Gets the node immediately preceding this node.
(Inherited from Node.) |
![]() ![]() | Properties |
A collection of the smart tag properties.
|
![]() ![]() | Range |
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.) |
![]() ![]() | Uri |
Specifies the namespace URI of the smart tag.
|
Name | Description | |
---|---|---|
![]() ![]() | Accept |
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).) |
![]() ![]() | AppendChild |
Adds the specified node to the end of the list of child nodes for this node.
(Inherited from CompositeNode.) |
![]() ![]() | Clone | (Inherited from Node.) |
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetAncestor(Type) |
Gets the first ancestor of the specified object type.
(Inherited from Node.) |
![]() ![]() | GetAncestor(NodeType) |
Gets the first ancestor of the specified NodeType.
(Inherited from Node.) |
![]() ![]() | GetChild |
Returns an Nth child node that matches the specified type.
(Inherited from CompositeNode.) |
![]() ![]() | GetChildNodes |
Returns a live collection of child nodes that match the specified type.
(Inherited from CompositeNode.) |
![]() ![]() | GetEnumerator |
Provides support for the for each style iteration over the child nodes of this node.
(Inherited from CompositeNode.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() ![]() | GetText |
Gets the text of this node and of all its children.
(Inherited from CompositeNode.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | IndexOf |
Returns the index of the specified child node in the child node array.
(Inherited from CompositeNode.) |
![]() ![]() | InsertAfter |
Inserts the specified node immediately after the specified reference node.
(Inherited from CompositeNode.) |
![]() ![]() | InsertBefore |
Inserts the specified node immediately before the specified reference node.
(Inherited from CompositeNode.) |
![]() ![]() | NextPreOrder |
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | PrependChild |
Adds the specified node to the beginning of the list of child nodes for this node.
(Inherited from CompositeNode.) |
![]() ![]() | PreviousPreOrder |
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | Remove |
Removes itself from the parent.
(Inherited from Node.) |
![]() ![]() | RemoveAllChildren |
Removes all the child nodes of the current node.
(Inherited from CompositeNode.) |
![]() ![]() | RemoveChild |
Removes the specified child node.
(Inherited from CompositeNode.) |
![]() ![]() | RemoveSmartTags |
Removes all SmartTag descendant nodes of the current node.
(Inherited from CompositeNode.) |
![]() ![]() | SelectNodes |
Selects a list of nodes matching the XPath expression.
(Inherited from CompositeNode.) |
![]() ![]() | SelectSingleNode |
Selects the first Node that matches the XPath expression.
(Inherited from CompositeNode.) |
![]() | ToString | (Inherited from Object.) |
![]() ![]() | ToString(SaveFormat) |
Exports the content of the node into a string in the specified format.
(Inherited from Node.) |
![]() ![]() | ToString(SaveOptions) |
Exports the content of the node into a string using the specified save options.
(Inherited from Node.) |
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.
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; } }